0

If I have a date in the following format within Bash

time="Mar 18 2020 01:15:19"

I need to find out if it is within a 30 minute of window the current date and time (i.e. has 30 minutes elapsed).

So if the current date time is "Mar 18 2020 01:45:00", it would evaluate to true.

However, if the current date time is "Mar 18 2020 02:00:00", it would evaluate to false.

How would I go about doing this?

methuselah
  • 12,766
  • 47
  • 165
  • 315
  • Does this answer your question? [How to calculate time elapsed in bash script?](https://stackoverflow.com/questions/8903239/how-to-calculate-time-elapsed-in-bash-script) – tomgalpin Mar 18 '20 at 11:36

1 Answers1

2

How would I go about doing this?

Convert the time to seconds since epoch.

Compare seconds.

time="Mar 18 2020 01:15:19"
if (( ($(date +%s) - $(date --date="$time" +%s)) < (30 * 60) )); then
     echo within;
else
    echo not within;
fi
KamilCuk
  • 120,984
  • 8
  • 59
  • 111