A
A
Alexander Nazarov2022-04-09 18:19:04
bash
Alexander Nazarov, 2022-04-09 18:19:04

How to compare dates in BASH?

There is a certain date: 2022-02-19 13:32:09
And there is a local date:
date +%Y-%m-%d\ %H:%M:%S

How to find out how many minutes have passed?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
X
xibir, 2022-04-09
@wergio

d=`date +%s -d '2022-02-19 13:32:09'`
echo $(( (`date +%s` - d) / 60 )) # количество минут от заданного до текущего времени

F
FanatPHP, 2022-04-09
@FanatPHP

1. google how to convert a date to a unix timestamp in bash
2. (optional) google how to get the current unix timestamp
3. subtract one from the other, get the difference in seconds
4. how to get minutes from seconds, I really hope you can overpower yourself

C
CityCat4, 2022-04-11
@CityCat4

Usually I don’t directly suggest the code, but here everything is as simple as a log:

_newcrl=`date -r $file1 +%s`
_oldcrl=`date -r $file2 +%s`

if [ $_newcrl -gt $_oldcrl ]; then
# тут делаем чегой-то
fi

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question