The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Calculate time to some date Sapfeer High Level Programming 4 07-08-2009 11:10 AM
Calculate date by week thans_guban Shell Programming and Scripting 2 10-28-2008 09:31 AM
calculate the date of next satureday of current date. rinku Shell Programming and Scripting 3 09-03-2008 12:05 AM
How to Calculate weekly date range mamta UNIX for Dummies Questions & Answers 1 03-06-2008 06:50 AM
How can I use mathematic calculate in date? guitaroa47 Shell Programming and Scripting 1 06-05-2007 08:37 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-24-2009
jimmy_y jimmy_y is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 94
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. Thanks
  #2 (permalink)  
Old 08-24-2009
Smiling Dragon's Avatar
Smiling Dragon Smiling Dragon is offline Forum Advisor  
Disorganised User
  
 

Join Date: Nov 2007
Location: New Zealand
Posts: 922
A quick search produced: Yesterdays Date/Date Arithmetic
  #3 (permalink)  
Old 08-25-2009
jimmy_y jimmy_y is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 94
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;

Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:08 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0