How to convert 10 digit mysql date to django date format

136 views
Skip to first unread message

laspal

unread,
May 22, 2009, 2:13:27 AM5/22/09
to Django users
Hi,

How to convert mysql 10 digit date format to django date format?
example:
mysql date - 1219848914
to django date - "22-05-09"


thanks.

googletorp

unread,
May 22, 2009, 2:54:43 AM5/22/09
to Django users
Hi
It looks like a unix timestamp. I cant remember what python uses to
convert unix to a date objecr but should be pretty simple. Maybe
strftime/strptime or you can just google it.

~Jakob

R. Gorman

unread,
May 22, 2009, 7:24:27 PM5/22/09
to Django users
As the previous post mentioned, I'm assuming that is a unix timestamp.
The module you want to use is datetime.

import datetime
mysql_date = datetime.datetime.fromtimestamp(1219848914)

mysql_date can be save directly to a datetime model field. However, if
you are wanting the date formatted as you provided, the last step
would be:

mysql_date.strftime("%d-%m-%y")

R.
Reply all
Reply to author
Forward
0 new messages