Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

comparing a date variable with a date field in a file

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have a script which interrogates & retrieves records from a file. The 1st field in the file is a date with format CCYY-MM-DD. At the moment, my script accepts a run-time date variable ( same format as above ) and compares this value with the dates on the file, & retrives matches.
if [[ $filedate = $variabledate ]]
then
etc etc
This works fine.

I now want to add a second date variable, and amend the test to select records within a range. But what is the syntax ?
I have tried
if [[ $filedate > $variabledate1 && $filedate < $variabledate2 ]]
but this returns records with filedate = variabledate1, and duplicates some of the retrieved fields !
if [[ $filedate > $variabledate1 ]] && [[ $filedate < $variabledate2 ]] gives a syntax error.
Please help
 
Change if [[ $filedate > $variabledate1 && $filedate < $variabledate2 ]]

to

if [ &quot;$filedate&quot; -gt &quot;$variabledate1&quot; -a &quot;$filedate&quot; -lt &quot;$variabledate2&quot; ]
then
some actions
fi


Bill.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top