Home Man
Search
Today's Posts
Register

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

compare dates using shell sript

Tags
shell scripts

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 05-13-2011
compare dates using shell sript

I have 2 date feilds
Code:
2011-05-13:18:45
2011-05-13:18:30

I need to compare them and say its OK/NOK

I tried this but dint work.
Code:
systime=2011-05-13:18:45
shubtime=2011-05-13:18:30
if [ "$systime" -eq "$shubtime" ]
then
         echo" OK"
else
         echo "NOK"
fi

In this its not same so the o/p should be NOK

Last edited by Scott; 05-13-2011 at 07:35 PM.. Reason: Added code tags
# 2  
Old 05-13-2011
Code:
ksh
systime=2011-05-13:18:45
shubtime=2011-05-13:18:45
echo $systime $shubtime | tr -d ':-' | read a b
[[ $a -eq $b ]] && echo OK || echo KO

The Following User Says Thank You to ctsgnb For This Useful Post:
LavanyaP (05-18-2011)
# 3  
Old 05-13-2011
If they must be exactly the same
Code:
systime=2011-05-13:18:45
shubtime=2011-05-13:18:30
if [ "$systime" = "$shubtime" ]
then
    echo" OK"
else
    echo "NOK"
fi

Or shorter:
Code:
[ "$systime" = "$shubtime" ] && echo" OK" || echo "NOK"

PS: please use code tags and indent your code
The Following User Says Thank You to frans For This Useful Post:
LavanyaP (05-18-2011)
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
compare dates skamal4u Shell Programming and Scripting 3 09-06-2009 10:55 AM
Compare dates necroman08 Shell Programming and Scripting 2 08-24-2009 05:15 AM
convert the below perl sript to shell script mail2sant Shell Programming and Scripting 1 04-04-2008 01:36 PM
Shell Sript jazz8146 UNIX for Dummies Questions & Answers 3 01-11-2008 01:07 PM
Compare two dates using Shell Programming dave_nithis Shell Programming and Scripting 4 01-04-2008 04:18 AM
Shell Sript - Spell Checker Assign ccfc1986 Shell Programming and Scripting 9 11-14-2007 11:52 PM
compare dates... i_priyank Shell Programming and Scripting 3 09-21-2007 12:50 AM
How to compare the dates in shell script vaji Shell Programming and Scripting 9 02-27-2007 11:34 PM
How to compare two dates bankpro Programming 5 01-24-2006 03:07 AM
compare two dates wchen Shell Programming and Scripting 6 10-24-2002 04:39 PM


All times are GMT -4. The time now is 05:58 PM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password