[Tutor] Using datetime module
Don Arnold
darnold02 at sprynet.com
Tue May 25 22:12:15 EDT 2004
A datetime.date object can be set to a given date by passing in the year,
month, and day as parameters when you create it. So, you could do something
like this:
import datetime
usrDate= raw_input("Enter the date (yyyy/mm/dd format): ")
T = int(raw_input("Enter how many days: "))
offset = datetime.timedelta(days=T)
yyyy = int(usrDate[0:4])
mm = int(usrDate[5:7])
dd = int(usrDate[8:])
usrDateObj = datetime.date(year=yyyy,month=mm,day=dd)
print '%s + %d days = %s' % (usrDateObj, T, usrDateObj + offset)
[-----begin script run-----]
Enter the date (yyyy/mm/dd format): 2004/01/01
Enter how many days: 59
2004-01-01 + 59 days = 2004-02-29
[-----end script run-----]
HTH,
Don
-----Original Message-----
From: tutor-bounces at python.org [mailto:tutor-bounces at python.org] On Behalf
Of acidblue
Sent: Tuesday, May 25, 2004 1:26 PM
To: tutor at python.org
Subject: [Tutor] Using datetime module
I'm trying to add dates together using datetime module.
I want usr's to enter a date and add a number of days to it.
Example:
import datetime
usrDate= input("Enter the date:")
T= input("Enter how many days:")
print datetime.date.today() + datetime.timedelta(days=T)
Obviosly the 'datetime.date.today()' only works for today's date What I
what is this:
Psuedo code: usrDate + datetime.timedelta(days=T)
Am I using the right module? Syntax? Arguments?
_______________________________________________
Tutor maillist - Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list