432,035 Members | 1,543 Online
Need help? Post your question and get tips & solutions from a community of 432,035 IT Pros & Developers. It's quick & easy.

# how do you manipulate the days on a calender

 P: 8 when I did this on hypercard all i had to do was: put the date into date convert date to secs(onds) date =+ (24*60*60*No_of_days_i_want_to_add_on) convert date to the date Is there any way I could do that with Python Jan 8 '14 #1
4 Replies

 Expert Mod 2.5K+ P: 2,851 Here's an example of using built-in modules datetime and time to parse a date string and add days: Expand|Select|Wrap|Line Numbers import datetime as dt import time   userDate = "2007/08/20" timeObj = time.strptime(userDate, "%Y/%m/%d") daysToAdd = 15 dateObj = dt.datetime(*timeObj[:6])   print dateObj print dateObj + dt.timedelta(days=daysToAdd) Jan 8 '14 #2

 P: 8 this works great thank you, you got me out of a bind again, I've looked it over and messed with it to see how it works, but I can't figer out why the Expand|Select|Wrap|Line Numbers [:6] as in Expand|Select|Wrap|Line Numbers dateObj = dt.datetime(*timeObj[:6]) also what is dt as in Expand|Select|Wrap|Line Numbers import datetime as dt Jan 9 '14 #3

 Expert Mod 2.5K+ P: 2,851 The time object has additional attributes that would not be accepted by the datetime.datetime constructor. That's why I take a slice of the time object ([:6]) which returns the first 6 elements. It works because a time object is iterable. "import datetime as dt" is a way to abbreviate datetime. Expand|Select|Wrap|Line Numbers >>> for attr in timeObj: ...     print attr ...      2007 8 20         232 -1 >>> timeObj[:6] (2007, 8, 20, 0, 0, 0) >>>  Jan 9 '14 #4

 P: 8 very cool thanks again Jan 9 '14 #5