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)?
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.
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.
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With