How to convert python date format to 10 digit date format for mysql?

how to convert python date format to 10 digit date format for mysql

Example: date in python -> 11-05-09

by about 1239992972 (10 digits)

thanks

0


a source to share


4 answers


You can use the strptime time module - you pass in a string time (like 11-05-09) and a format and it will return a struct_time from which you can get a numeric value (by calling time.mktime on the returned struct_time). See the docs fortime.strptime

details .



+4


a source


If it's a datetime obj you can do:

import time
time.mktime(datetime_obj.timetuple())

      



If not:

time.mktime(time.strptime("11-05-09", "%d-%m-%y"))

      

+2


a source


Use time.strptime () to convert the date to a temporary tuple and then time.mktime () (or calendar.timegm ()) to convert it to floating point time. You will probably have to truncate it to an integer after.

tm = time.strptime('11-05-09', '%d-%m-%y')
time = time.mktime(tm)
time_int = int(time)

      

http://docs.python.org/library/time.html

0


a source


You can use easy_date to make it simpler:

import date_converter
timestamp = date_converter.string_to_timestamp('11-05-09','%d-%m-%y')

      

0


a source







All Articles