date duration fail to calculate


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting date duration fail to calculate
# 1  
Old 08-24-2009
date duration fail to calculate

Hi Everyone,

I was very sad after a long way but still cannot figure out the duration between two date.
Code:
$date1="20090812 23:48:56";
$date2="20090813 00:01:37";

The output will be "001241".

I did the following tries, like print localtime(UnixDate(ParseDate("20090812 23:48:56"),"%s")); and other ways to calculate the differience, but :--(

Please advice. ThanksSmilie
# 2  
Old 08-24-2009
# 3  
Old 08-25-2009
Below is the finally code, hope this is the most simple method.
i have two date, i want to get the duration in to hhmmss format. Below is the working code.

Code:
$a = localtime(UnixDate(ParseDate("20090823 08:03:35"),"%s"));
$b = localtime(UnixDate(ParseDate("20090823 12:04:55"),"%s"));
$c = str2time($b)-str2time($a);
$hms=sprintf("%02d%02d%02d",int($c/3600),int($c%3600/60),int($c%60));
print $hms;

Image
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

How to calculate the quarter end date according to the current date in shell script?

Hi, My question is how to calculate the quarter end date according to the current date in shell script? (2 Replies)
Discussion started by: Divya_1234
2 Replies

2. UNIX for Beginners Questions & Answers

How to calculate time duration in Linux?

I want to calculate duration for below file in this format SID | Date | Starttime |Date |End time 1607 |2019-04-05|13:06:42|2019-04-05|13:07:12 2327 |2019-04-05|13:57:26|2019-04-05|13:57:43 O/p should be like this: SID | Date | Starttime |Date |Endtime... (4 Replies)
Discussion started by: anupmishra
4 Replies

3. Shell Programming and Scripting

Calculate Julian date of a given date

How to get Julian date (Three digit) of a given date (Not current date)? I do not have root privilege - so can not use date -d. Assume that we have three variables year, month and date. Thx (5 Replies)
Discussion started by: Soham
5 Replies

4. UNIX for Dummies Questions & Answers

Script shell calculate mean arrival request duration

hello, I have implemented this command : tshark -eth0 -T fiels -e frame.time et sip.Request-Line -z sip,stat > test2.txt the result of this command : test.txt: Aug 27, 2013 23:06:47.334270000 INVITE Aug 27, 2013 23:06:47.335045000 SIP/2.0 401 Unauthorized Aug 27, 2013... (1 Reply)
Discussion started by: Amouna
1 Replies

5. Shell Programming and Scripting

Getting the Start, End time and duration using date command

Oracle Enterprise Linux We want to track how long a process takes to complete its execution. This is what we want in the schell script Before the process is started , get the time with date, hours and minutes execute the process After the process has ended , get the time with date,... (5 Replies)
Discussion started by: omega3
5 Replies

6. Shell Programming and Scripting

Convert Date from File and Calculate Duration

Hi - I am looking for a little help to read in 2 date fields from a file in format: 20120508134012.3 yyyymmddhhmmss.tenths of a second So i want to: 1. Read in the 1st date from the file 2. Read in the second date from the file 3. Calculate the difference in minutes (or seconds) 4. ... (5 Replies)
Discussion started by: Newbie2012
5 Replies

7. Shell Programming and Scripting

Calculate date

Hello, i need calculate the day before in this format aammdd, for example if i have 110701 i need a script to return the value 110630. I only know what with this comand "date %y%m%d" return the date system. Sorry for my english, it is very bad, i know... Thank you very much Grettings! (1 Reply)
Discussion started by: Xedrox
1 Replies

8. Programming

Calculate the current date.

Give your an integer (e.g. 0x0076f676) representing the number of minutes elapsed since January 1, 1996. How to calculate the current date which format should be "year-month-day-hour-minutes" ? (3 Replies)
Discussion started by: qcmao
3 Replies

9. Shell Programming and Scripting

calculate the date of next satureday of current date.

I want to calculate the date of next satureday of current date using shell script. Suppose, today is 27-feb-08 I want to get the date of next satureday, which means 01-mar-08, in the formate '' YYMMDD ". I do this in ksh.. Please tell me any type of command which help me out. Thanks in... (3 Replies)
Discussion started by: rinku
3 Replies

10. Shell Programming and Scripting

How can I use mathematic calculate in date?

Hi all, All I need to do is calculate the system date to my desire date. My case is everyday in my system , it will receive ftp file from another unix server. If I issued 'date' for today it will return this : -bash-3.00$ date +%Y%m%d 20070605 but the ftp file that receive everyday... (1 Reply)
Discussion started by: guitaroa47
1 Replies
Login or Register to Ask a Question