Skip to content

Instantly share code, notes, and snippets.

@hborders
Created September 14, 2016 18:16
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hborders/cf29e4a6878a72c14a0898578ac92538 to your computer and use it in GitHub Desktop.
Save hborders/cf29e4a6878a72c14a0898578ac92538 to your computer and use it in GitHub Desktop.
Print the number of minutes since a given date
#!/bin/bash -euo pipefail
if [ ${#} -eq 0 ]
then
# read from STDIN
DATE=$( cat )
else
DATE="${1}"
fi
SECONDS_FROM_EPOCH_TO_NOW=$( date "+%s" )
SECONDS_FROM_EPOCH_TO_DATE=$( date -j -f "%b %d %Y %T %Z" "${DATE}" "+%s" )
MINUTES_SINCE_DATE=$(( $(( ${SECONDS_FROM_EPOCH_TO_NOW}-${SECONDS_FROM_EPOCH_TO_DATE} ))/60 ))
echo "${MINUTES_SINCE_DATE}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment