Solved

Bash - compare 2 dates

Posted on 2007-04-04
6
2,552 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unix / Linux grid computing 5 167
Help with a backup script in Linux 4 76
Cron jobs 12 139
Windows shortcut location resolution on double click open 4 47
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

679 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