Help with date and time diff


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with date and time diff
# 1  
Old 09-19-2002
Help with date and time diff

Hi ,

Can somebody please help me with this.
The date format is in MM/DD/YY HH24:MI:SS

suppose I have a start_date=09/03/02 04:15:02
& Finish date= 09/04/02 07:13:51

I want to find out the difference between the two ie finish_time-start time.
How can I do this.
Morever I want the output in HH:MI:SI as well.

Thanks
Rooh
# 2  
Old 09-19-2002
How about:
Code:
#! /usr/bin/ksh

typeset -Z2 ehour eminute esecond

Start="09/03/02 04:15:02"
Finish="09/04/02 07:13:51"

IFS=" /:"
echo $Start | read smonth sday syear shour sminute ssecond
echo $Finish | read fmonth fday fyear fhour fminute fsecond
IFS=""

((syear=syear+2000))
((fyear=fyear+2000))
sjd=$(datecalc -j $syear $smonth $sday)
fjd=$(datecalc -j $fyear $fmonth $fday)
((days=fjd-sjd))
((extra=days*24))
((start=((shour*60)+sminute)*60+ssecond))
((finish=(((extra+fhour)*60)+fminute)*60+fsecond))
((elasped=finish-start))
((ehour=elasped/3600))
((elasped=elasped%3600))
((eminute=elasped/60))
((esecond=elasped%60))

echo $Finish
echo $Start
echo ${ehour}:${eminute}:${esecond}
exit 0

This uses my datecalc script which I have previously posted.
# 3  
Old 09-19-2002
I did a google search and found this Perl module:

http://catcode.com/date/pcalc.html

Perhaps that's of use to you?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Calculate Time diff in milli milliseconds(Time format : HH:MM:SS,NNN)

Hi All, I have one file which contains time for request and response. I want to calculate time difference in milliseconds for each line. This file can contain 10K lines. Sample file with 4 lines. for first line. Request Time: 15:23:45,255 Response Time: 15:23:45,258 Time diff... (6 Replies)
Discussion started by: Raza Ali
6 Replies

2. Shell Programming and Scripting

Diff between two time in hours in last column

Dear All I want to diff between two time(FIRST 4 COLUMN) in hours in last column. Kindly help me for same. 2013-11-23 15:51:23 2013-11-23 12:20:06 BRC023 CG 2013-11-23 15:51:23 2013-11-23 12:20:08 BRC064CG 2013-11-23 15:51:23 2013-11-22 13:17:49 BLM003 NG 2013-11-23 15:51:23 2013-11-22... (9 Replies)
Discussion started by: jaydeep_sadaria
9 Replies

3. Shell Programming and Scripting

Time Stap Diff using Bash

hi all kindly i want to subtract to time stamps like: t1=08:35:20 t2=08:36:58 diff=00:01:38 <<<< or diff=01:38 <<<< using bash thanks alot (9 Replies)
Discussion started by: teefa
9 Replies

4. Shell Programming and Scripting

Time Diff in shell script

Hi all , i am trying to calculate time difference btw the script execution I am using solaris start_time=`date +%s` sleep 2 end_time=`date +%s` duration=`expr $end_time - $start_time` when i try to subtract i get the error line 13: %s - -time : syntax error: operand expected... (3 Replies)
Discussion started by: posner
3 Replies

5. Linux

diff date

Hi, One script is giving the date which is not contstant. and the need is to compare it with the current one and find the diff. if it is less than 15 days , need to send an e-mail. Date format coming from the script is October 24, 2055 Thanks (1 Reply)
Discussion started by: nagendramv
1 Replies

6. Shell Programming and Scripting

to find the diff in a date

Hello, i have a variable where the present date is going to save. and i have another variable where the another date which will of higher value is going to save. I need to find the difference with respect to date,month and year. What the need is to send an e-mail if the difference in... (2 Replies)
Discussion started by: nagendramv
2 Replies

7. Shell Programming and Scripting

time diff help

Input file: Tue Oct 21 12:56:35 2008 Started Tue Oct 21 12:56:39 2008 Completed Tue Oct 21 12:57:25 2008 Started Tue Oct 21 12:57:32 2008 Completed Tue Oct 21 12:58:12 2008 Started Tue Oct 21 12:58:50 2008 Completed Output required: Tue Oct 21 12:56:35 2008 Started Tue Oct 21... (2 Replies)
Discussion started by: uwork72
2 Replies

8. Shell Programming and Scripting

diff in date/time ?

the o/p is : Start Time: 2008-02-19 00:13:16,338 End Time: 2008-02-19 23:43:17,974 How to find the diff in time..........? (1 Reply)
Discussion started by: ali560045
1 Replies

9. UNIX for Advanced & Expert Users

Diff b/w modification & updated time

Hi All, What is the difference b/w last modification time and last updated time. Thanks Sweta (1 Reply)
Discussion started by: sweta
1 Replies

10. Shell Programming and Scripting

how to look in directory for files with diff date

What kind of command can i use to search a directory and subdirectories for all files that do not have the same date? i want to find any files that do not match a date of Sep 13, 2002? Or that have a different owner or group? Any help appreciated! (2 Replies)
Discussion started by: kymberm
2 Replies
Login or Register to Ask a Question