Created
August 28, 2013 09:11
-
-
Save carlosescri/6363927 to your computer and use it in GitHub Desktop.
Create a datetime from a string in a given format.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from datetime import datetime | |
def str_to_datetime(str_date, str_format="%Y-%m-%d %H:%M"): | |
""" Creates a datetime from a string in a given format. """ | |
dt = time.strptime(str_date, str_format) | |
dt = time.mktime(dt) | |
return datetime.fromtimestamp(dt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment