Solved

Bash - compare 2 dates

Posted on 2007-04-04
6
2,557 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
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!

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
what is this linux system is? 16 123
Doc'in system (example?) BA 7 127
Cron jobs 12 145
matchUp  challenge 9 134
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

751 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