Compare Date with String in date format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare Date with String in date format
# 1  
Old 03-30-2013
Compare Date with String in date format

Hi,
I am new to this forum, searched, but for some reason did not find much help, so a new thread.

I am trying to compare date with a string which is in date format [dd-mm-yyyy], but for some reason, system does not give me the right result.

Date is coming in a file and i am comparing the same with today date. If they match, we are good, if not, we have a problem.

date in the file store as fd and today date as td. Both are in dd-mm-yyyy formats.

if [ $fd <> $td ] then
echo "File received does not contains current data, Please check"
else
echo "File has been downloaded with today data"
fi

above loop always goes in first statement even if the the variable contains same date string.

Any help would be appreciated.

Last edited by mkstool; 03-30-2013 at 07:02 PM..
# 2  
Old 03-30-2013
Use operator != instead:
Code:
if [ "$fd" != "$td" ]
then
      # action
else
      # action
fi

For further reference: String Comparison Operators
# 3  
Old 03-30-2013
<> is a BASIC thing, haven't seen it much in other languages.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Date: invalid date trying to set Linux date in specific format

i try to set linux date & time in specific format but it keep giving me error Example : date "+%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" or date +"%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" keep giving me this error : date: invalid date ‘19-01-2017 00:05:01' Please use CODE tags... (7 Replies)
Discussion started by: umen
7 Replies

2. Shell Programming and Scripting

Show the string in date format

Hello guys. how can print the: 20140206 like Fri, Feb 6, 2015 Thank you. (4 Replies)
Discussion started by: Ymir
4 Replies

3. Shell Programming and Scripting

Convert string into date format

Hi, I am getting the below string as a input for date. 12/03/2013 11:02 AM I want to change this date as 03-DEC-2013 11:02 AM. Could you please help on this. Thanks Chelladurai (4 Replies)
Discussion started by: ckchelladurai
4 Replies

4. UNIX for Dummies Questions & Answers

Rename all Files in a UNIX Directory from one date format to another date format

Hi Unix Gurus, I would like to rename several files in a Unix Directory . The filenames can have more than 1 underscore ( _ ) and the last underscore is always followed by a date in the format mmddyyyy. The Extension of the files can be .txt or .pdf or .xls etc and is case insensitive ie... (1 Reply)
Discussion started by: pchegoor
1 Replies

5. Shell Programming and Scripting

awk compare column with date format

I have this code to compare columns 1 and 10 between file1 and file 2 and give me all records that match column 1 but dont match column 10 However column 10 is date format mm/dd/yy and awk cant read it and compare ...i tried awk < file1 -F~ '{print $10}' and it gave blank screen Is... (1 Reply)
Discussion started by: sigh2010
1 Replies

6. UNIX for Dummies Questions & Answers

Changing from Excel date format to MySQL date format

I have a list of dates in the following format: mm/dd/yyyy and want to change these to the MySQL standard format: yyyy-mm-dd. The dates in the original file may or may not be zero padded, so April is sometimes "04" and other times simply "4". This is what I use to change the format: sed -i '' -e... (2 Replies)
Discussion started by: figaro
2 Replies

7. Shell Programming and Scripting

change date format and then compare dates

I have filenames filenameA_fg_MMDDYY.tar.gz filenameASPQ_fg_MMDDYY.tar.gz filenameAFTOPHYYINGH_fg_MMDDYY.tar.gz filenameAGHYSW_fg_MMDDYY.tar.gz My requiremnt needs to extract date which is in MMDDYYand change it into YYYYMMDD format. I have done the following: filedate=`echo... (5 Replies)
Discussion started by: RubinPat
5 Replies

8. Shell Programming and Scripting

Which is the STRING format in the date command?

Hi According with the 'date' command documentation My question is, which are the possible values for STRING? I have been looking in the man pages but I didn't find anything? After some googling I have found it can have special values as 'now', 'yesterday' or 'tomorrow'. If it represents... (1 Reply)
Discussion started by: islegmar
1 Replies

9. Shell Programming and Scripting

convert date format to mysql date format in log file

I have a comma delimited log file which has the date as MM/DD/YY in the 2nd column, and HH:MM:SS in the 3rd column. I need to change the date format to YYYY-MM-DD and merge it with the the time HH:MM:SS. How will I got about this? Sample input 02/27/09,23:52:31 02/27/09,23:52:52... (3 Replies)
Discussion started by: hazno
3 Replies

10. UNIX for Dummies Questions & Answers

How to format a date string

I have a file tmp.out with contents: 20080812 02:41:07 20080812 05:03:04 20080812 05:46:16 How do I format the contents such as: 2008-08-12 02:41:07 2008-08-12 05:03:04 2008-08-12 05:46:16 Thanks, - CB (2 Replies)
Discussion started by: ChicagoBlues
2 Replies
Login or Register to Ask a Question