Solved

Bash - compare 2 dates

Posted on 2007-04-04
6
2,549 Views
Last Modified: 2013-12-26
Hello,
How can i compare 2 dates?

└─(~)-> date
Thu Apr  5 06:13:35 UTC 2007

This one, with a pre-given one (pregivendate="5 May 2007")
(i just want to compare the day, month and year)
Something like ...
if date is greater than the pregivendate; then stop else do something

Thanx
0
Comment
Question by:rares_dumitrescu
  • 3
  • 3
6 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 18856068
test `date +%Y%m%d` -gt 20070505 && do something
0
 

Author Comment

by:rares_dumitrescu
ID: 18856100
and .. at the end .. how can i split 20070505 into 2007 / 05 / 05 ?
0
 
LVL 84

Expert Comment

by:ozo
ID: 18856131
date +'%Y / %m / %d'
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:rares_dumitrescu
ID: 18856145
ah .. not the date .. the other one
here is the script

date=`date +%m%d%Y`
expd="02052007"

if [ "$date" -gt "$expd" ]; then
echo "Your script has expired in: !here i want the 02052007 splitted into 02 / 05 / 2006! (Month /  Day / Year)"
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 18856189
expy=2007
expm=02
expd=05
date=`date +%Y%m%d`
if [ "$date" -gt "$expy$expm$expd" ]; then
echo "Your script has expired in: $expm / $expd / $expy! (Month /  Day / Year)"
fi
0
 

Author Comment

by:rares_dumitrescu
ID: 18856252
thanx ozo, you've been great, like always :)
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
"uptime" high (200+) on RHEL6 but CPU usage is low... any ideas why? 4 106
centeredAverage challenge 8 178
matchUp  challenge 9 115
sumHeights  challenge 17 73
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question