comparing two times


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers comparing two times
# 1  
Old 07-18-2009
comparing two times

Hi Good Morning all,

I have two dates and times in the beloe format.
1. 07/18/2009 03:45:49
2. 07/18/2009 03:46:41

i will grep these values from a file. Now my problem is i need to find out whether the second valus is bigger thatn the 1 value. How to compare the times. Please help me in this.

Thanks in advance.

Raju
# 2  
Old 07-18-2009
Hint:convert time in sec or min then compare
# 3  
Old 07-18-2009
Code:
#!/bin/ksh93

date1="07/18/2009 03:45:49"
date2="07/18/2009 03:46:41"

if (( $(printf "%(%s)T" "$date1") < $(printf "%(%s)T" "$date2") ))
then
    echo "date2 is after date2"
else
    echo "date2 is not after date1"
fi

# 4  
Old 07-20-2009
Quote:
Originally Posted by fpmurphy
Code:
#!/bin/ksh93
 
date1="07/18/2009 03:45:49"
date2="07/18/2009 03:46:41"
 
if (( $(printf "%(%s)T" "$date1") < $(printf "%(%s)T" "$date2") ))
then
    echo "date2 is after date2"
else
    echo "date2 is not after date1"
fi


Hi Thanks for the reply.

I got a little problem with the code.
i wrote the command you gave to me. but while i am trying to ececute to the script if says the syntax errro. and the line number it shows is the line where IF condition is there. Please help me in this.
# 5  
Old 07-21-2009
What shell are you using?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Response Times

Hello all. Let me qualify my question by saying that I am struggling with how to ask the question I am semi green but have no issue reading up if pointed in the right direction. Please be gentle! A RHEL server 6.2. Hosts a statistical application that has some web apps and batch programming... (0 Replies)
Discussion started by: rsheikh01
0 Replies

2. Shell Programming and Scripting

To get difference between 2 times.

Can anyone help me to write a script to get diffrence between 2 times. (platform- solaris) i.e., Diffence shoud be displayed in tems of hours. (Approximately) for eg: file1 = 05-Apr-2012 13:42:32 file2 = 04-Apr-2012 12:42:41 O/P is like : diff = 25 Hrs (2 Replies)
Discussion started by: thomasraj87
2 Replies

3. Programming

Problem with implementing the times() function in C (struct tms times return zero/negative values)

Hello, i'm trying to implement the times() function and i'm programming in C. I'm using the "struct tms" structure which consists of the fields: The tms_utime structure member is the CPU time charged for the execution of user instructions of the calling process. The tms_stime structure... (1 Reply)
Discussion started by: g_p
1 Replies

4. HP-UX

grep for x for m times ',\{11\}'

All: OS version HP-UX ga016a501 B.11.31 U ia64 from the command prompt -grep for 1 to 11 occurences of "," returns both rows from the command prompt -grep for 11 occurences of "," returns 0 rows - should be 1 row. Any ideas - why? ga016a501 -> grep ',\{1,11\}' test3 | more ... (7 Replies)
Discussion started by: Bill L.
7 Replies

5. Shell Programming and Scripting

Executes many times

The code prints many times, "1st loop" and "2nd loop". How can I come out the if the condition is matched. Match should be only once and it should come out of the loop if the match is found time=$(date +"%H:%M:%S") echo $time while : do if then echo "1st loop" fi if then... (5 Replies)
Discussion started by: sandy1028
5 Replies

6. Shell Programming and Scripting

finding out how many times something comes up

Hi, I have a file that looks something like this: YPA124 NV YPA124 NV YPA124 V YAR198 V YAR198 V YOB911 V YOB911 V YOB911 NV YOB911 NA So what i want to do is find out how many times each name on column 1 is represented by indicators on column 2. So the output would... (4 Replies)
Discussion started by: phil_heath
4 Replies

7. Shell Programming and Scripting

Getting logs between two times

Hi, I need to read log file for the period between two time frame.eg all those logs between 3AM to 4M. Any command to use for the shell scripting? Ahamed (5 Replies)
Discussion started by: ahamed
5 Replies

8. Shell Programming and Scripting

script for comparing the times.

Hi, My below output file looks like this. Backup status at Tue Jul 7 03:30:07 EDT 2009 CMLP Job Name Last Start Last End ST Run Pri/Xit ____________________________ ____________________ ____________________ __ _______ ___ tnx415uu 07/06/2009 22:01:41 ----- RU 5547800/1 tnp415uu 07/06/2009... (2 Replies)
Discussion started by: intiraju
2 Replies

9. AIX

how would you know your server was rebooted 3 times or 5 times

Is there such location or command to know how many times did you reboot your server in that particular day?in AIX. (3 Replies)
Discussion started by: kenshinhimura
3 Replies

10. Shell Programming and Scripting

Question about times and so

I've got an logfile like: Start dump db_name1 : Wed Oct 30 15:08:47 MET 2002 Ready dump db_name1 : Wed Oct 30 15:14:46 MET 2002 Start dump db_name2 : Wed Oct 30 15:14:46 MET 2002 Ready dump db_name2 : Wed Oct 30 15:15:36 MET 2002 Start dump db_name3 : Wed Oct 30 15:15:36 MET 2002... (1 Reply)
Discussion started by: TheBlueLady
1 Replies
Login or Register to Ask a Question