Comparing different time formats


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Comparing different time formats
# 1  
Old 03-25-2016
Comparing different time formats

I am trying to do a comparison of files based on their last modified date.

I am pulling the first file from a webapp folder using curl.

Code:
curl --silent -I http://localhost:8023/conf/log4j2.xml | grep Last
Last-Modified: Tue, 22 Mar 2016 22:02:18 GMT

The second file is on local disk.

Code:
stat /var/tmp/log4j2.xml  | grep Modify | awk '{print $2" "$3}' | cut -d'.' -f1
2016-03-24 13:56:51

Is there a mechanism to convert the times ? So that I can then compare the two times and take an action accordingly.
# 2  
Old 03-25-2016
Hi.

To what granularity? Same year? Same month? Day? Hour?, etc.

Best wishes ... cheers, drl
This User Gave Thanks to drl For This Post:
# 3  
Old 03-25-2016
Day Month Hour Minute

I found something like this which gives me the same format. Thats what I needed.

Code:
    OLD=`date --date="$OLD_TIME"`
    NEW=`date --date="$NEW_TIME"`


Last edited by Don Cragun; 03-26-2016 at 04:58 AM.. Reason: Add CODE tags.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Parse apache log file with three different time formats

Hi, I want to parse below file and Write a function to extract the logs between two given timestamp. Apache (Unix) Log Samples - MonitorWare The challenge here is there are three date and time format. First :- 07/Mar/2004:16:05:49 Second :- Sun Mar 7 16:02:00 2004 Third :- 29-Mar... (6 Replies)
Discussion started by: sahil_shine
6 Replies

2. UNIX for Beginners Questions & Answers

Comparing time differences between 2 Solaris servers

Good day to all. I'm relatively new in using the Sun Solaris OS. I would like to request your expertise in helping to solve a problem that I have at work. Not sure if this has been asked before but I have tried searching through the internet to no avail. Basically I have 2 sun solaris... (8 Replies)
Discussion started by: Fossil_84
8 Replies

3. 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

4. Shell Programming and Scripting

Comparing time is bash

Hi, I have a question on comparing time using bash. Tried searching a lot up but couldn't figure it out. So I have this: CURRENT_TIME=$(date +%H:%M) if then echo "Continue" else echo "Quit" fi I tried a lot of different combinations of comparing, but nothing seems to work. Any help... (2 Replies)
Discussion started by: r4v3n
2 Replies

5. Shell Programming and Scripting

Comparing Time

I want to write a shell script which will run when a new terminal is opened and will display Good Morning or Good Evening depending on the current time? (2 Replies)
Discussion started by: shounakdas
2 Replies

6. Shell Programming and Scripting

Setting of two time formats in one machine

Hi, Is it possible to set the two time formats in a single machine. My machine time is in EST and the logs are in PST. What would be the issue, and how to make change of this.? (5 Replies)
Discussion started by: gsiva
5 Replies

7. Shell Programming and Scripting

comparing time stamps

Hello All, I'm generating timestamps (file creation timestamps) for all the files in a directory. I need to compare all the timestamps. for example if i have 4 files and their timestamps are 20091125114556, 20091125114556,20091125114556,20091125114556 respectively. I need to differentiate... (9 Replies)
Discussion started by: RSC1985
9 Replies

8. UNIX for Dummies Questions & Answers

comparing time stamps

Hello All, I'm generating timestamps (file creation timestamps) for all the files in a directory. I need to compare all the timestamps. for example if i have 4 files and their timestamps are 20091125114556, 20091125114556,20091125114556,20091125114556 respectively. I need to differentiate... (1 Reply)
Discussion started by: RSC1985
1 Replies

9. UNIX for Dummies Questions & Answers

Comparing Time

Hi guys, Is there a way whereby i can grep the last updated time of a log file and compare it with the server time? Thanks (5 Replies)
Discussion started by: hanyou.lin
5 Replies

10. UNIX for Dummies Questions & Answers

Comparing time in unix

Hi All, i have two variables with date/time in the following format: 07/09/08 02:38:32 (mm/dd/yy hh:mm:ss). I need to do a comparison to find latest one. Can anyone please help me? Regards, G1 (2 Replies)
Discussion started by: jeevan_fimare
2 Replies
Login or Register to Ask a Question