parsing a date
peter at commonlawgov.org
Sat Sep 24 01:40:58 CEST 2005
Kalle Anke wrote:
>I want to parse a date string, for example '2005-09-23', and since I haven't
>done this before I would like to ask what is the best way to do it.
>I've looked around and the dateutil seems to be what most people use, but
>unfortunately I only get an empty file when I try to download it. I also
>tried the standard modules and ended up with this
>from time import strptime
>d = '2005-09-23'
>w = strptime(d,'%Y-%m-%d')
>print datetime.date( w, w, w )
Well, thats not _to_ bad.
>But I suspect there is a better way to do it??
I would check out "strftime"
With strftime you could do something like this...
or if you wanted to get the time in the past or future you could do
tm = time.localtime(time.time() + ((60 * 60) * 24))
print strftime("%Y-%m-%d", tm)
Which gets the date of tommarow.
More information about the Python-list