Skip to content

Instantly share code, notes, and snippets.

@stalinkay
Forked from hborders/minutes_since_date.bash
Created February 17, 2022 23:11
Show Gist options
  • Save stalinkay/7c19ef8c94ab81b29be17249552e0875 to your computer and use it in GitHub Desktop.
Save stalinkay/7c19ef8c94ab81b29be17249552e0875 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