how to convert python date format to 10 digit date format for mysql
example: date in python -> 11-05-09
to something like 1239992972 (10 digit)
Thanks
You can use the time module's strptime - you pass in a string time (e.g. 11-05-09) and a format and it will return a struct_time, which you can get the numerical value from (by calling time.mktime on the returned struct_time). See the docs for time.strptime for further details.
Use time.strptime() to convert the date into a time tuple, and then time.mktime() (or calendar.timegm()) to convert that into a floating point time. You'll probably need to truncate it to an integer after.
tm = time.strptime('11-05-09', '%d-%m-%y')
time = time.mktime(tm)
time_int = int(time)
You can use easy_date to make it easy:
import date_converter
timestamp = date_converter.string_to_timestamp('11-05-09','%d-%m-%y')