datetime string conversion error
python at mrabarnett.plus.com
Tue Mar 16 20:53:20 CET 2010
Jordan Apgar wrote:
> Hey all,
> I'm trying to convert a string to a date time object and all my fields
> convert except for month which seems to default to january.
> here's what I'm doing:
> date = "2010-03-16 14:46:38.409137"
> olddate = datetime.strptime(date,"%Y-%m-%j %H:%M:%S.%f")
> print date
> print olddate
> I get:
> 2010-03-16 14:46:38.409137
> 2010-01-16 14:46:38.409137
> notice the 01 in the second date from what I could tell everything is
> formatted correctly.
The problem seems to be related to your use of "%j", which parses the
day of the year.
If I use "%d" instead, which parses the day of the month (I think that's
what you intended!), then the month comes out as 3 as expected.
More information about the Python-list