#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    3
    Rep Power
    0

    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. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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.
    programming language development: www.netytan.com Hula

  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    3
    Rep Power
    0

    Returning a specific date in year


    Thanksgiving is always on the fourth Thursday in November, so incrementing the year will not work.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    133
    Rep Power
    11
    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.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    3
    Rep Power
    0

    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.

IMN logo majestic logo threadwatch logo seochat tools logo