Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 19th, 2004, 08:29 AM
achterberg achterberg is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 3 achterberg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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.

Reply With Quote
  #2  
Old June 19th, 2004, 10:47 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,536 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 3 m 4 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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


Reply With Quote
  #3  
Old June 19th, 2004, 05:21 PM
achterberg achterberg is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 3 achterberg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Returning a specific date in year

Thanksgiving is always on the fourth Thursday in November, so incrementing the year will not work.

Reply With Quote
  #4  
Old June 19th, 2004, 05:36 PM
percivall percivall is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 133 percivall User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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.

Reply With Quote
  #5  
Old June 20th, 2004, 03:22 PM
achterberg achterberg is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 3 achterberg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Returning a specific date in year


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT