Comparing to Date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Comparing to Date
# 1  
Old 08-22-2008
Comparing to Date

Hi ,
I need to compare the given date with the system date . can you tell me any way , how to do it.

The given date format is "23-AUG-2008".

I need to compare it with the system time , i have got the system time in the same format by using the command "date +%e-%b-%y" ,its giving the date as "23-Aug-2008".

I'm nt getting the desired output. Can anyone help me out.
I'm using the following piece of code

variable="23-AUG-08"
variable2=`date +%e-%b-%y`
if [ $variable2 \< $variable ]
then
echo "worked"


else
echo "didnot "
fi


Is this piece of code correct ??? or there is another way to do it ????
# 2  
Old 08-22-2008
try
Code:
variable2=`date +%e-%b-%y | tr -s '[:lower:]' '[:upper:]'`

to change to uppercase

In general comparing dates like that will not work, search the forums for 'comparing dates'
# 3  
Old 08-22-2008
You can use the format YYYYMMDD to compare the date:

Code:
variable="20080823"
variable2=`date "+%Y%m%d"`
if [ $variable2 \< $variable ]

Regards
# 4  
Old 08-22-2008
Thank you both , i used the command to make them to Uppercase , and now my problem is solved.

Thanks alot :-)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comparing files by date/time

I am trying to compare identically named files in different directories and replace a file only with a newer version. Is there a way of doing this? TIA (4 Replies)
Discussion started by: wbport
4 Replies

2. Shell Programming and Scripting

Comparing date and check minute difference

Dear all, I'm stuck on Solaris 9 bash (I believe is quite different from Linux system) trying to find a solution. I have one file named like:120629-1750-TERZ81_AS_YTR.txt YYMMDD-HH-MM-......The script should compare the actual date with the one reported on the file name and then take an action... (4 Replies)
Discussion started by: Lord Spectre
4 Replies

3. Shell Programming and Scripting

comparing variables to date as string

I have a file $ cat myfile A 02/16/2012 B 02/19/2012 C 02/20/2012 D 02/17/2012 E 02/16/2012 My simple script > cat myscript.sh mydate="02/16/2012" awk ' ($2~/$mydate/) {print $1}' < myfile but I got no output! and when I try $2~/'$mydate'/ I got: The error context is (2 Replies)
Discussion started by: Sara_84
2 Replies

4. UNIX for Dummies Questions & Answers

Comparing Output Date to Current System Date

Hi Guys, Anyone who knows how to compare the current date with the a file containing a date, say for example I have a file that looks like this: Command was launched from partition 0. ------------------------------------------------ Executing command in server server6 Fri Dec 16... (7 Replies)
Discussion started by: rymnd_12345
7 Replies

5. Shell Programming and Scripting

Need help in Shell Script comparing todays date with Yesterday date from Sysdate

Hi, I want to compare today's date(DDMMYYYY) with yesterday(DDMMYYYY) from system date,if (today month = yesterday month) then execute alter query else do nothing. The above requirement i want in Shell script(KSH)... Can any one please help me? Double post, continued here. (0 Replies)
Discussion started by: kumarmsk1331
0 Replies

6. Shell Programming and Scripting

Comparing current date

Hi, I have start date and end date in the following format. I need to check the current date is greater than the start date and less than the end date. if i use the command date --date "Tue 6:00 AM", it takes next Tues day not the current week's Tues day. Is there a way to get the current Tues... (9 Replies)
Discussion started by: bharathappriyan
9 Replies

7. Emergency UNIX and Linux Support

Comparing date values stored in a file

Hi all, I have written a script which stores data along with requisite dates in a file. I need to compare the stored date values in the file to obtain the row with the highest date value i.e. the recent most entered record in the file. Please help cause i dont know how we can compare dates in... (10 Replies)
Discussion started by: sumi_mn
10 Replies

8. Linux

Comparing the file drop date with todays date

Daily one file will dropped into this directory. Directory: /opt/app/jt/drop File name: XXXX_<timestamp>.dat.gz I need to write a script which checks whether the file is dropped daily or not. Any idea in the script how can we compare timestamp of the file to today's date?? (3 Replies)
Discussion started by: Rajneel
3 Replies

9. Shell Programming and Scripting

Perl: Extracting date from file name and comparing with current date

I need to extract the date part from the file name (20080221 in this ex) and compare it with the current date and delete it, if it is a past date. $file = exp_ABCD4_T-2584780_upto_20080221.dmp.Z really appreciate any help. thanks mkneni (4 Replies)
Discussion started by: MKNENI
4 Replies

10. UNIX for Dummies Questions & Answers

Bash comparing date

Cound anyone help me on how to compare date in Unix using if function on bash file? current=date if ###syntax is wrong, could anyone correct it for me then rm -rf /usr/local/src fi Thank You... (17 Replies)
Discussion started by: Stanford Co
17 Replies
Login or Register to Ask a Question