Solved

Bash - compare 2 dates

Posted on 2007-04-04
6
2,531 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

708 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now