Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python, Convert 9 tuple UTC date to MySQL datetime format

I am parsing RSS feeds with the format as specified here: http://www.feedparser.org/docs/date-parsing.html

date tuple (2009, 3, 23, 13, 6, 34, 0, 82, 0)

I am a bit stumped at how to get this into the MySQL datetime format (Y-m-d H:M:S)?

like image 311
NeonNinja Avatar asked Mar 26 '09 17:03

NeonNinja


People also ask

How do you use UTC datetime in Python?

Getting the UTC timestampUse the datetime. datetime. now() to get the current date and time. Then use tzinfo class to convert our datetime to UTC.

How do I convert a datetime to a specific date in python?

Use datetime. strftime(format) to convert a datetime object into a string as per the corresponding format . The format codes are standard directives for mentioning in which format you want to represent datetime. For example, the %d-%m-%Y %H:%M:%S codes convert date to dd-mm-yyyy hh:mm:ss format.


1 Answers

tup = (2009, 3, 23, 13, 6, 34, 0, 82, 0)
import datetime 
d = datetime.datetime(*(tup[0:6]))
#two equivalent ways to format it:
dStr = d.isoformat(' ')
#or
dStr = d.strftime('%Y-%m-%d %H:%M:%S')
like image 190
vartec Avatar answered Oct 23 '22 15:10

vartec