|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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.197045can any one help me to get the time stamp difference of these two line in seconds. |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
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 12:05 AM.. |
| The Following User Says Thank You to balajesuri For This Useful Post: | ||
netdbaind (02-12-2013) | ||
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
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
|
|||
|
|||
|
thanks balajesuri ur code worked!
can you plz explain ur code. |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
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 )) |
| Sponsored Links | ||
|
![]() |
| Tags |
| time stamp |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| System time and Cron time stamp not matching | karghum | Solaris | 4 | 04-25-2012 07:50 AM |
| How to get time duration between two human readable time stamp in Unix? | ford99 | Shell Programming and Scripting | 3 | 07-19-2011 09:52 AM |
| Calculate time stamp difference | bharath.phatak | Shell Programming and Scripting | 4 | 07-12-2011 08:15 AM |
| regarding time stamp | aishsimplesweet | Shell Programming and Scripting | 3 | 01-28-2011 09:58 AM |
| Calculate the Time stamp difference | firestar | Shell Programming and Scripting | 2 | 09-08-2010 04:18 AM |
|
|