Skip to content

Instantly share code, notes, and snippets.

@PierreAlainKouakou
Forked from morion4000/countdown.py
Created September 18, 2023 18:42
Show Gist options
  • Save PierreAlainKouakou/67dd730a97675ec14edeb779bf9ca2d1 to your computer and use it in GitHub Desktop.
Save PierreAlainKouakou/67dd730a97675ec14edeb779bf9ca2d1 to your computer and use it in GitHub Desktop.
Python countdown to date script
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