LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Bash command for comparing two dates (https://www.linuxquestions.org/questions/linux-software-2/bash-command-for-comparing-two-dates-4175455530/)

Completely Clueless 03-25-2013 12:00 PM

Bash command for comparing two dates
 
Hi all,

Is there a command in Bash that allows one to compare the current date grabbed from the network with another one specified in a script file?
I cannot use cron since the hardware in question will not be running constantly and anacron from what I can see doesn't parse dates at all; merely intervals which isn't sufficient in this case.

Any ideas; suggestions for workarounds?

thanks, cc.

H_TeXMeX_H 03-25-2013 01:12 PM

Yes, the 'date' command is what you want.

Here are some examples:
http://unix.stackexchange.com/questi...te-differences

you can search for more. It depends on what exactly you want to calculate.

Completely Clueless 03-25-2013 01:56 PM

Quote:

Originally Posted by H_TeXMeX_H (Post 4918567)
Yes, the 'date' command is what you want.

Here are some examples:
http://unix.stackexchange.com/questi...te-differences

you can search for more. It depends on what exactly you want to calculate.

Thank you, TM. I had no idea "date" was so versatile! How the hell do you find all this stuff? My searches never seem to bear any fruit. :(

H_TeXMeX_H 03-25-2013 01:59 PM

It wasn't that easy to find. You're lucking I was looking for exactly the same thing just yesterday for a script I was making.

Habitual 03-25-2013 02:27 PM

http://www.linuxquestions.org/questi...es-4175454050/

short version:
Code:

echo $((($(date +%s -d "June 5, 2013")-$(date +%s -d "June 5, 1960"))/86400)) days.
19358 days.

Habitual 03-25-2013 02:34 PM

Quote:

Originally Posted by Completely Clueless (Post 4918592)
How the hell do you find all this stuff?

sadly, it is the old standby answer "RTFM".
in "man bash" and "man date" to be specific.

w1k0 03-25-2013 06:34 PM

See: that thread.


All times are GMT -5. The time now is 07:00 PM.