Skip to content

Instantly share code, notes, and snippets.

@jay-johnson
Last active June 4, 2016 02:42
Show Gist options
  • Select an option

  • Save jay-johnson/6a041694abc010d67f5af65cd5b4fa20 to your computer and use it in GitHub Desktop.

Select an option

Save jay-johnson/6a041694abc010d67f5af65cd5b4fa20 to your computer and use it in GitHub Desktop.
Python Date Transformations

A list of python data transformations

String to Datetime

  1. String to Datetime and then compare
#!/usr/bin/python

import datetime

cur     = datetime.datetime.now().strftime("%Y-%m-%d")
future  = datetime.datetime.strptime(cur + " 16:01:00", "%Y-%m-%d %H:%M:%S")
compare = datetime.datetime.strptime(cur + " 16:02:00", "%Y-%m-%d %H:%M:%S")

print compare > future
print compare < future
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment