Date/Time Conversion

Mike Brown mike at skew.org
Thu Nov 7 18:58:51 EST 2002


"dapmco" <webmaster at clasp.org> wrote in message
news:eeAy9.46$4G5.20100 at news.abs.net...
> Thanks Paul.. That worked fine. I looked at the docs but could not figure
> out how to do this. A couple of routines looked like they would work but I
> couldnt seem to invoke them on my Windows platform
>
> Input a date in some format ex 01/01/1990..
> Return the number of seconds between 01/01/1970 and the date entered.

Yeah, Windows doesn't have time.strptime().
Try something like this...

import re, time
s = '01/01/90'
pat = re.compile(r'(\d+)/(\d+)/(\d+)')
m,d,y = pat.match(s).groups() # assuming USA (month first)
y = int(y)
y += 1900 + 100 * (y < 70) # Beware! Y2.07K bug!
secs = time.mktime((y,int(m),int(d),0,0,0,0,0,0))






More information about the Python-list mailing list