Skip to content

Instantly share code, notes, and snippets.

@r1beast02
Last active August 29, 2015 14:08
Show Gist options
  • Save r1beast02/d9fadcf1f880a66ac142 to your computer and use it in GitHub Desktop.
Save r1beast02/d9fadcf1f880a66ac142 to your computer and use it in GitHub Desktop.
NYE
#!/bin/bash
# retrieve difference seconds for new years day and today's date from epoch
nye=$( date -d "Jan 1 2015" +%s)
today=$( date +"%s")
# get difference in seconds between 2 moments and convert to days/hours/minutes/seconds
seconds=$(($nye - $today))
days=$(($seconds / 86400))
seconds=$(($seconds % 86400))
hours=$(($seconds / 3600))
seconds=$(($seconds % 3600))
minutes=$(($seconds / 60))
seconds=$(($seconds % 60))
echo "$days day(s) $hours hour(s) $minutes minute(s) $seconds second(s) until New Year's"!
@SeanPlusPlus
Copy link

👍

@gsharp
Copy link

gsharp commented Oct 29, 2014

dope! you have seconds declared a lot I was wondering if you used % for a reason?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment