Skip to content

Instantly share code, notes, and snippets.

@mbierman
Last active September 8, 2022 00:09
Show Gist options
  • Save mbierman/f81b591fd27638b9f4221e9525229eca to your computer and use it in GitHub Desktop.
Save mbierman/f81b591fd27638b9f4221e9525229eca to your computer and use it in GitHub Desktop.
Gets epoc dates for some number of minutes and hours you select before now. Mostly created for plaing with Firewalla MSP API
#!/bin/bash
# v 1.0.1
# https://gist.github.com/mbierman/f81b591fd27638b9f4221e9525229eca
echo -e "How many minutes before now?"
read minutes
# min=$(date -v-${minutes}M +%s)
minutes=${minutes:=0}
echo -e "You entered $minutes minutes\n\n"
echo -e "How many hours before now?"
read hours
hours=${hours:=0}
echo -e "You entered $hours hours\n\n"
start=$(date -v-${minutes}M -v-${hours}H +%s)
startFull=$(date -v-${minutes}M -v-${hours}H '+%A, %B %d, %Y %H:%M')
end=$(date +%s)
endFull=$(date '+%A, %B %d, %Y %H:%M')
echo -e "Start: $start $startFull\nEnd: $end $endFull\n"
@mbierman
Copy link
Author

mbierman commented Sep 6, 2022

Example

$ epocdate.sh 
How many minutes before now?
1
You entered 1 minutes


How many hours before now?
1
You entered 1 hours


Start: 1662444808 Monday, September 05, 2022 23:13
End:   1662448468 Tuesday, September 06, 2022 00:14

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