On Fri, Aug 21, 2009 at 11:44 PM, Ronn Ross<ronn.r...@gmail.com> wrote: > I'm new to python and I'm getting a date time from a field in the database > that looks like this: > 8/2/2009 8:36:16 AM (UTC) > > I want to split it into two fields one with the date formatted like this: > YYYY-MM-DDÂ 2009-08-02 > > and the time to be 24 hour or military time. How every you call it. Similar > to this: > 15:22:00 > > I found it easy to truncate off the (UTC), but having trouble converting the > date. Can someone point me in the right direction? >
datetime.datetime.strptime() will give you a datetime object, which you can then format in a wide variety of ways using its strftime() method. Doesn't work with dates earlier than 1900, I believe. -- kushal -- http://mail.python.org/mailman/listinfo/python-list