[Answered ]-Parse string as date-time

2👍

You can use datetime to achieve what you are looking for

from datetime import datetime 
date_string = "Sat, 14 Sep 2013 22:44:49 +0000"
initial_format = "%a, %w %b %Y %H:%M:%S %z"
final_format = "%Y-%m-%d %H:%M:%S %z" 

datetime.strptime(date_string, initial_format).strftime(final_format)

You can construct the appropriate formats here

Alternatively, for django models, you could just send datetime object as a parameter, and django would convert it to the appropriate format for you.

Leave a comment