date / time

Jeff Shannon jeff at ccvcorp.com
Wed Apr 3 15:32:09 EST 2002


In article <a8elrm$r7du9$3 at ID-41653.news.dfncis.de>, klausman-
un070202 at tuts.net says...
> mixo <mixo at beth.uniforum.org.za> wrote:
> > 
> > Suppose there is a given date, 2002-03-01 (YYYY-MM-DD).
> > How can you get the day (2002-02-28 ) before the given date and
> > check that it is valid?
> 
> (I replace the interpreters >>> prompt with ### for better
>  legibility in USENET posts)
> 
> ### import time
> ### date="2002-03-01"
> ### time.strptime(date,"%Y-%m-%d")
> (2002, 3, 1, 0, 0, 0, 4, 60, 0)

A word of warning about time.strptime(), from the library 
reference:

: Note: This function relies entirely on the underlying
: platform's C library for the date parsing, and some of these 
: libraries are buggy. There's nothing to be done about this 
: short of a new, portable implementation of strptime(). 
: 
: Availability: Most modern Unix systems. 

So, this will not work on Windows (I believe there is a 
strptime() implementation for Windows, but you'd have to hunt it 
down), and depending on your system libraries, even if it *does* 
exist it may be buggy.  (Perhaps this explains your 1-sec-off 
problem?)

-- 

Jeff Shannon
Technician/Programmer
Credit International



More information about the Python-list mailing list