|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Returning a specific date in year
I am developing a Plone site for an annual festival which occurs on the second weekend of November, every year (actually, the second Saturday before Thanksgiving). I am new to python but I have at least figured out how to get, add and subtract time
![]() What I want, though, is to know how to get the date of the festival every year using a Python script. I have: from DateTime import DateTime # Saturday start date1 = DateTime('2004/11/13 9:00:00 US/Central') and I want the 2004/11/13 to be calculated every year. Several dates (registration deadlines, etc.) are based on this date and I would like to get it automagically every year rather than re-coding everything annually. I have tried playing around with the calendar, but have become so confused that I need a push in the right direction. |
|
#2
|
||||
|
||||
|
Sorry i'm a little comfused, this may be due to not being american and having no 'thanks giving' but is this festival on the same day each year? If so i don't see a problem at all, all you would have to do is increment the year by one each year.
Have fun, Mark. |
|
#3
|
|||
|
|||
|
Returning a specific date in year
Thanksgiving is always on the fourth Thursday in November, so incrementing the year will not work.
|
|
#4
|
|||
|
|||
|
Well. One way is the calendar module:
Code:
>>> import calendar >>> calendar.monthcalendar(2004, 11) [[1, 2, 3, 4, 5, 6, 7], [8, 9, 10, 11, 12, 13, 14], [15, 16, 17, 18, 19, 20, 21], [22, 23, 24, 25, 26, 27, 28], [29, 30, 0, 0, 0, 0, 0]] >>> calendar.monthcalendar(2004, 11)[1][-1] 14 That'll get you the second sunday of the month. Another way is: Code:
>>> firstday = datetime.date(2004, 11, 1).weekday() >>> 7 - firstday + 7 14 This will give you the second sunday of the month as well. This means that the fourth Thursday of november is: Code:
>>> firstday = datetime.date(2004, 11, 1).weekday() >>> 4 - firstday + 7 + 7 + 7 25 Last edited by percivall : June 19th, 2004 at 05:51 PM. |
|
#5
|
|||
|
|||
|
Returning a specific date in year
Thanks for the reply. Snippets of code like this go far in helping understand code. I can take it on from here.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Returning a specific date in year |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|