Solved

Bash - compare 2 dates

Posted on 2007-04-04
6
2,568 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

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

Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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. …
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.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

615 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