Re: How Compute # of Days between Two Dates?
On 2008-09-01, W. eWatson <[EMAIL PROTECTED]> wrote: > Oddly, Leaning Python has no mention of datetime (not date or time), at > least, that I could find. I'm considering the Nutshell book, 2nd ed., as a > better reference (and cross reference) to various topics. datetime is pretty new standard library module. I'm quite sure that it wasn't around when the latest edition of Learning Python was written. -- Ari Makela late autumn - [EMAIL PROTECTED] a single chair waiting http://arska.org/hauva/ for someone yet to come -- Arima Akito -- http://mail.python.org/mailman/listinfo/python-list
Re: How Compute # of Days between Two Dates?
Grant Edwards wrote: On 2008-09-01, W. eWatson <[EMAIL PROTECTED]> wrote: Grant Edwards wrote: On 2008-09-01, W. eWatson <[EMAIL PROTECTED]> wrote: That's the question in Subject. For example, the difference between 08/29/2008 and 09/03/2008 is +5. The difference between 02/28/2008 and 03/03/2008 is 4, leap year--extra day in Feb. I'm really only interested in years between, say, 1990 and 2050. In other words not some really strange period of time well outside our current era of history. Does the standard library's datetime module not do what you want? http://docs.python.org/lib/module-datetime.html Yes, it would seem so. This works fine. It would probably be worth your while to read through one of introductory Python books or just browse through the Python tutorial: http://docs.python.org/tut/ Oddly, Leaning Python has no mention of datetime (not date or time), at least, that I could find. I'm considering the Nutshell book, 2nd ed., as a better reference (and cross reference) to various topics. I was pondering this in pyfdate, but perhaps missed it or it was not obvious to me in the tutorial for some reason. Sorry, can't help you there -- I've never heard of pyfdate. The timedate module that comes with Python has always done what I needed to do with dates/times. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet Web Page: -- http://mail.python.org/mailman/listinfo/python-list
Re: How Compute # of Days between Two Dates?
On 2008-09-01, W. eWatson <[EMAIL PROTECTED]> wrote: > Grant Edwards wrote: >> On 2008-09-01, W. eWatson <[EMAIL PROTECTED]> wrote: >> >>> That's the question in Subject. For example, the difference between >>> 08/29/2008 and 09/03/2008 is +5. The difference between 02/28/2008 and >>> 03/03/2008 is 4, leap year--extra day in Feb. I'm really only interested in >>> years between, say, 1990 and 2050. In other words not some really strange >>> period of time well outside our current era of history. >> >> Does the standard library's datetime module not do what you want? >> >> http://docs.python.org/lib/module-datetime.html >> > Yes, it would seem so. This works fine. It would probably be worth your while to read through one of introductory Python books or just browse through the Python tutorial: http://docs.python.org/tut/ > I was pondering this in pyfdate, but perhaps missed it or it > was not obvious to me in the tutorial for some reason. Sorry, can't help you there -- I've never heard of pyfdate. The timedate module that comes with Python has always done what I needed to do with dates/times. -- Grant -- http://mail.python.org/mailman/listinfo/python-list
Re: How Compute # of Days between Two Dates?
Grant Edwards wrote: On 2008-09-01, W. eWatson <[EMAIL PROTECTED]> wrote: That's the question in Subject. For example, the difference between 08/29/2008 and 09/03/2008 is +5. The difference between 02/28/2008 and 03/03/2008 is 4, leap year--extra day in Feb. I'm really only interested in years between, say, 1990 and 2050. In other words not some really strange period of time well outside our current era of history. Does the standard library's datetime module not do what you want? http://docs.python.org/lib/module-datetime.html Yes, it would seem so. This works fine. date1 = datetime.date(2007, 2, 27) date2 = datetime.date(2007, 3, 3) print "date1: ", date1 print "date2: ", date2 diff = date2 - date1 print "diff: ", diff result: date1: 2007-02-27 date2: 2007-03-03 diff: 4 days, 0:00:00 I was pondering this in pyfdate, but perhaps missed it or it was not obvious to me in the tutorial for some reason. There are few places where it's not quite complete. pyfdate has some rules for dealing with length of month oddities that started me thinking it would have difficulty with situations like the above. However, it would seem any general implementation of time and date should be capable of making similar calculations without difficulty. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet Web Page: -- http://mail.python.org/mailman/listinfo/python-list
Re: How Compute # of Days between Two Dates?
On 2008-09-01, W. eWatson <[EMAIL PROTECTED]> wrote: > That's the question in Subject. For example, the difference between > 08/29/2008 and 09/03/2008 is +5. The difference between 02/28/2008 and > 03/03/2008 is 4, leap year--extra day in Feb. I'm really only interested in > years between, say, 1990 and 2050. In other words not some really strange > period of time well outside our current era of history. Does the standard library's datetime module not do what you want? http://docs.python.org/lib/module-datetime.html -- Grant -- http://mail.python.org/mailman/listinfo/python-list
Re: How Compute # of Days between Two Dates?
from datetime import datetime # batteries included today = datetime.now() xmas = datetime(today.year,12,25) if (xmas - today).days > 1: print "%d days until Christmas" % (xmas - today).days else: print "Merry Christmas!" -- http://mail.python.org/mailman/listinfo/python-list
Re: How Compute # of Days between Two Dates?
Have you tried using subtraction on datetime.date objects (http://docs.python.org/lib/datetime-date.html)? It produces a timedelta which should be very close to what you want. - Chris On Sun, Aug 31, 2008 at 7:38 PM, W. eWatson <[EMAIL PROTECTED]> wrote: > That's the question in Subject. For example, the difference between > 08/29/2008 and 09/03/2008 is +5. The difference between 02/28/2008 and > 03/03/2008 is 4, leap year--extra day in Feb. I'm really only interested in > years between, say, 1990 and 2050. In other words not some really strange > period of time well outside our current era of history. > > -- > W. eWatson > > (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) > Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet > >Web Page: > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Follow the path of the Iguana... http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
How Compute # of Days between Two Dates?
That's the question in Subject. For example, the difference between 08/29/2008 and 09/03/2008 is +5. The difference between 02/28/2008 and 03/03/2008 is 4, leap year--extra day in Feb. I'm really only interested in years between, say, 1990 and 2050. In other words not some really strange period of time well outside our current era of history. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet Web Page: -- http://mail.python.org/mailman/listinfo/python-list