LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-25-2013, 12:00 PM   #1
Completely Clueless
Member
 
Registered: Mar 2008
Location: Marbella, Spain
Distribution: Many and various...
Posts: 899

Rep: Reputation: 70
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.

Last edited by Completely Clueless; 03-25-2013 at 12:23 PM.
 
Old 03-25-2013, 01:12 PM   #2
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
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.
 
1 members found this post helpful.
Old 03-25-2013, 01:56 PM   #3
Completely Clueless
Member
 
Registered: Mar 2008
Location: Marbella, Spain
Distribution: Many and various...
Posts: 899

Original Poster
Rep: Reputation: 70
Quote:
Originally Posted by H_TeXMeX_H View Post
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.
 
Old 03-25-2013, 01:59 PM   #4
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
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.
 
Old 03-25-2013, 02:27 PM   #5
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
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.
 
Old 03-25-2013, 02:34 PM   #6
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by Completely Clueless View Post
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.
 
Old 03-25-2013, 06:34 PM   #7
w1k0
Senior Member
 
Registered: May 2008
Location: Poland
Distribution: Slackware (personalized Window Maker), Mint (customized MATE)
Posts: 1,309

Rep: Reputation: 234Reputation: 234Reputation: 234
See: that thread.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
python: comparing dates stateless Programming 1 03-11-2013 04:25 PM
Comparing arrays in bash unihiekka Linux - Newbie 4 06-03-2010 06:08 AM
Bash Scripting with Dates MrBriz Programming 13 11-23-2008 03:04 PM
Comparing dates with ruby lmcilwain Programming 5 03-10-2007 02:29 PM
bash - comparing a variable to several values davee Programming 3 05-05-2003 07:26 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration