Created
October 10, 2012 15:33
-
-
Save morion4000/3866374 to your computer and use it in GitHub Desktop.
Python countdown to date script
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
from datetime import datetime, time | |
def dateDiffInSeconds(date1, date2): | |
timedelta = date2 - date1 | |
return timedelta.days * 24 * 3600 + timedelta.seconds | |
def daysHoursMinutesSecondsFromSeconds(seconds): | |
minutes, seconds = divmod(seconds, 60) | |
hours, minutes = divmod(minutes, 60) | |
days, hours = divmod(hours, 24) | |
return (days, hours, minutes, seconds) | |
leaving_date = datetime.strptime('2012-01-01 01:00:00', '%Y-%m-%d %H:%M:%S') | |
now = datetime.now() | |
print "%d days, %d hours, %d minutes, %d seconds" % daysHoursMinutesSecondsFromSeconds(dateDiffInSeconds(now, leaving_date)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here you go