Timestamp comparison


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Timestamp comparison
# 1  
Old 12-15-2008
Timestamp comparison

How do I compare 2 timestamps (ie... if 2008-02-13 10:48:58.502075 gt 2008-12-15 16:00:00.000000)
# 2  
Old 12-15-2008
Quote:
Originally Posted by auzark
How do I compare 2 timestamps (ie... if 2008-02-13 10:48:58.502075 gt 2008-12-15 16:00:00.000000)

The easiest way is to use GNU date:

Code:
ts1="2008-02-13 10:48:58.502075"
ts2="2008-12-15 16:00:00.000000"

[ $( date -d "$ts1" +%s ) -gt $( date -d "$ts2" +%s ) ]

# 3  
Old 12-15-2008
Thanks, but this does not work in Unix on AIX
# 4  
Old 12-15-2008
Quote:
Originally Posted by auzark
Thanks, but this does not work in Unix on AIX

Sometimes GNU date is installed as gdate.

Or you can install it from ftp://ftp.gnu.org/gnu/coreutils/ftp:...gnu/coreutils/

Otherwise you have to convert it yourself. (I have shell functions to convert dates to Julian days at 8: The Dating Game)

To convert the time portion:

printf "%s\n" "10:48:58.502075" | awk -F: '{ print $1 * 3600 + $2 * 60 + $3 }'
# 5  
Old 12-15-2008
Thanks, for your help, I'll have a go at the conversion to Julian. We do not have gdate installed nor do I have the authority to install it
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep lines between last hour timestamp and current timestamp

So basically I have a log file and each line in this log file starts with a timestamp: MON DD HH:MM:SS SEP 15 07:30:01 I need to grep all the lines between last hour timestamp and current timestamp. Then these lines will be moved to a tmp file from which I will grep for particular strings. ... (1 Reply)
Discussion started by: nms
1 Replies

2. Shell Programming and Scripting

AIX : Need to convert UNIX Timestamp to normal timestamp

Hello , I am working on AIX. I have to convert Unix timestamp to normal timestamp. Below is the file. The Unix timestamp will always be preceded by EFFECTIVE_TIME as first field as shown and there could be multiple EFFECTIVE_TIME in the file : 3.txt Contents of... (6 Replies)
Discussion started by: rahul2662
6 Replies

3. Shell Programming and Scripting

To check timestamp in logfile and display lines upto 3 hours before current timestamp

Hi Friends, I have the following logfile. Currently time in india is 07/31/2014 12:33:34 and i have the following content in logfile. I want to display only those entries which contain string 'Exception' within last 3 hours. In this case, it would be the last line only I can get the... (12 Replies)
Discussion started by: srkmish
12 Replies

4. Shell Programming and Scripting

Comparison of timestamp on ftp

Hello Need help with shell script There is are files on my ftp. They overwriting every hour from other places. ls -la /home/ftp/ -rw-r--r-- 1 ftp nogroup 2296 2012-08-11 12:59 G1.zip -rw-r--r-- 1 ftp nogroup 6676 2012-08-11 13:00 KRT1.zip -rw-r--r-- 1 ftp nogroup 5169... (3 Replies)
Discussion started by: ck80
3 Replies

5. Shell Programming and Scripting

Identifying files with a timestamp greater than a given timestamp

I need to be able to identify files with file timestamps greater than a given timestamp. I am using the following solution, although it appears to compare files at the "seconds" granularity and I need it at the milliseconds. When I tested my solution, it missed files that had timestamps... (3 Replies)
Discussion started by: nkm0brm
3 Replies

6. UNIX for Dummies Questions & Answers

How to compare a file by its timestamp and store in a different location whenever timestamp changes?

Hi All, I am new to unix programming. I am trying for a requirement and the requirement goes like this..... I have a test folder. Which tracks log files. After certain time, the log file is getting overwritten by another file (randomly as the time interval is not periodic). I need to preserve... (2 Replies)
Discussion started by: mailsara
2 Replies

7. Shell Programming and Scripting

Getting a relative timestamp from timestamp stored in a file

Hi, I've a file in the following format 1999-APR-8 17:31:06 1500 3 45 1999-APR-8 17:31:15 1500 3 45 1999-APR-8 17:31:25 1500 3 45 1999-APR-8 17:31:30 1500 3 45 1999-APR-8 17:31:55 1500 3 45 1999-APR-8 17:32:06 1500 3 ... (1 Reply)
Discussion started by: vaibhavkorde
1 Replies

8. Shell Programming and Scripting

Comparison of a timestamp and mtime of a file

Hi, I am a beginner in shell scripting. Could any one help me out for below requirement. Its bit urgent. Problem scenario: 1) I have a predefined timestamp (Ex. 2011-03-010 10:10:20) 2) And I have files in a directory starting with 'a' (Ex. a_123.txt, a_124.txt) Expected solution: I... (1 Reply)
Discussion started by: itzsamz
1 Replies

9. Shell Programming and Scripting

Timestamp comparison of 2 files present in 2 different servers

Hi, I have 2 different log servers and logs are stored in both of them at varied times. Those servers have same files stored at different times. I want to retrieve the latest of the log files that are stored inthe servers. Say "file.log" is present on both servers, i want to check which of it is... (3 Replies)
Discussion started by: goutham4u
3 Replies

10. Shell Programming and Scripting

Timestamp comparison

Hi all, below is my sample log file 02.20.38 .CASH_I_0069 RPM_RUN_DISTRIBUTION RPM_RUN_DISTRIBUTION 0001 1987 Started at 02.19.11 at node IEREDS17, Pid = 00492972 02.50.39 .CASH_I_0054 RPM_RUN_DISTRIBUTION RPM_RUN_DISTRIBUTION 0001 1987 Completed at 02.49.13, code: 00000000 at node IEREDS17,... (1 Reply)
Discussion started by: zainravi
1 Replies
Login or Register to Ask a Question