Time stamp Difference


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Time stamp Difference
# 1  
Old 02-11-2013
Time stamp Difference

I have a log file which wrote time stamp like this

Code:
2013-02-11 00:46:40.389037 
 
         2013-02-12 11:46:40.197045


can any one help me to get the time stamp difference of these two line in seconds.
# 2  
Old 02-11-2013
Code:
to=$(date -d "2013-02-12 11:46:40.197045" +%s)
from=$(date -d "2013-02-11 00:46:40.389037" +%s)
echo $(( $to - $from ))


Last edited by balajesuri; 02-12-2013 at 01:05 AM..
This User Gave Thanks to balajesuri For This Post:
# 3  
Old 02-11-2013
Hi, for calculare the difference between two date you must convert them in epoch with a code like this and then operate the difference
Code:
HOUR=12
MIN=41
SEC=11
DAY=01
MONTH=01
YEAR=2012
set -A MONTHS 0 0 31 59 90 120 151 181 212 243 273 304 334 365
echo "b=0;if(${MONTH}>2) if (${YEAR}%4==0) b=1; ${SEC}+${MIN}*60+${HOUR}*3600+(${MONTHS[${MONTH}]} + ${DAY} + b-1)*86400+(${YEAR}-1970)*31536000+((${YEAR}-1969)/4)*86400" | bc

# 4  
Old 02-12-2013
thanks balajesuri ur code worked!

can you plz explain ur code.
# 5  
Old 02-12-2013
Code:
# Calculate the time in seconds from epoch and store the value in "to". Check man date to see what switch -d and format %s do.
to=$(date -d "2013-02-12 11:46:40.197045" +%s)
from=$(date -d "2013-02-11 00:46:40.389037" +%s)

# Calculate the difference.
echo $(( $to - $from ))

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Difference between time stamp

Hi All i have a file data like below format A, B 2016-04-14 16:30:00,2016-04-14 16:31:17 2016-04-14 16:40:00,2016-04-14 16:41:10 2016-04-14 16:50:00,2016-04-14 16:50:41 2016-04-14 17:00:00,2016-04-14 17:00:35 2016-04-14 17:10:00,2016-04-14 17:11:48 2016-04-14 17:20:00,2016-04-14 17:20:37 i... (2 Replies)
Discussion started by: Tarak_nath
2 Replies

2. Shell Programming and Scripting

Logs between two time stamp

I am creating log monitoring script and stuck up to get the logs between two time stamp. can you please help me to create the script to get the logs between two time stamp, for example, I need the complete logs between # Time: 150328 1:30:10 and # Time: 150328 19:10:57 OS : Cent OS 6.x... (8 Replies)
Discussion started by: zenkarthi
8 Replies

3. Solaris

System time and Cron time stamp not matching

On Solaris 10 server the system date won't match with the timestamp on files created by a cron jobs, Please help here is what i get when i check for system date infodba-ie10ux014:/tcpdv1_ie10/tcadmin/bin\n\r-> date Tue Apr 24 15:27:43 GMT 2012at same time i executed a cron job, and checked... (4 Replies)
Discussion started by: karghum
4 Replies

4. Shell Programming and Scripting

How to get time duration between two human readable time stamp in Unix?

Here is two time I have: Jul 12 16:02:01 Jul 13 01:02:01 and how can I do a simple match to get difference between two time which is 09:00:00 Thanks in advance. (3 Replies)
Discussion started by: ford99
3 Replies

5. Shell Programming and Scripting

Calculate time stamp difference

Hi All, I am new to shell scripting.I have to write a shell script for the problem statement: "A file is updated continously. If it is not updated for a day then an error message needs to pop up." So the script needs to read the last modified time of that file and current system time .If... (4 Replies)
Discussion started by: bharath.phatak
4 Replies

6. Shell Programming and Scripting

regarding time stamp

hi everyone i am facing a strange problem here suppose content of my file is a=1,2,3 b=2,3,4 c=4,5,6 time= now the problem is i want to add value in front of time variable and the value should be i format only "HHMMSS" so it should be like this a=1,2,3 b=2,3,4 c=4,5,6... (3 Replies)
Discussion started by: aishsimplesweet
3 Replies

7. Shell Programming and Scripting

Calculate the Time stamp difference

hi, I have a log file which gives time stamps hh:mm:ss.sssss format in which hh- hours , mm -minutes ss.sssss - seconds.microseconds I need to calculate the time diff between sent time stamp and received time stamp .... could any one please help me.. i am tryin to write a script but... (2 Replies)
Discussion started by: firestar
2 Replies

8. UNIX for Dummies Questions & Answers

How to get the next time stamp in perl?

Hi, I have to find the next time stamp in perl. Here is the code. @time = loaltime(time); print "\n Present time: $time:$time:$time \n"; For example if the time is: "12:55:02" after some process the time becomes 1:00:00. How do i check when it becomes 00:00 i.e from "12:55:02... (0 Replies)
Discussion started by: vanitham
0 Replies

9. UNIX for Dummies Questions & Answers

checking time stamp

Hi, I am having a script in which I am again calling a script, but before calling that script I need to perform a time check (say 1 - 2 am i.e. I would be able to call that script if time is between 1:00 am and 2:00 am) but this time stamp needs to be configurable. can anybody suggest me how... (7 Replies)
Discussion started by: Manvar Khan
7 Replies

10. UNIX for Dummies Questions & Answers

Date/Time Stamp

Hi All, Wondering if there is have a date added at the end of a test string. I have a hypothetical text file day one: John Paul George When the file day one is output, I'd like it to read something like this: John 101406 Paul 101406 George 101406 Day two, when the same text file... (0 Replies)
Discussion started by: JimmyFlip
0 Replies
Login or Register to Ask a Question