[PHP] Determine the difference between two dates
If I have two variables of time both in the format of Y-m-j J:i:s How would I go about and get the difference? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Determine the difference between two dates
Firstly, I assume you mean Y-m-j H:i:s for the date format. To get the difference between 2 time strings : ?php // orginal time strings $firstTime=2002-04-19 13:49:00; $lastTime=2002-04-19 14:00:00; // convert to unix timestamps $firstTime=strtotime($firstTime); $lastTime=strtotime($lastTime); // perform subtraction to get the difference (in seconds) between times $timeDiff=$lastTime-$firstTime; //echo out the difference printf (Difference is %d seconds,$timeDiff); ? HTH Danny. - Original Message - From: Ron Allen [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, April 19, 2002 1:08 PM Subject: [PHP] Determine the difference between two dates If I have two variables of time both in the format of Y-m-j J:i:s How would I go about and get the difference? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Determine the difference between two dates
*This message was transferred with a trial version of CommuniGate(tm) Pro* Yes, but note that strtotime has a second parameter, which is now if not indicated. What strtotime returns is relative to this second parameter. I would use: $ahora = time(); $firstTime=strtotime($firstTime, $ahora); $lastTime=strtotime($lastTime, $ahora); Pedro. Danny Shepherd escribió: *This message was transferred with a trial version of CommuniGate(tm) Pro* Firstly, I assume you mean Y-m-j H:i:s for the date format. To get the difference between 2 time strings : ?php // orginal time strings $firstTime=2002-04-19 13:49:00; $lastTime=2002-04-19 14:00:00; // convert to unix timestamps $firstTime=strtotime($firstTime); $lastTime=strtotime($lastTime); // perform subtraction to get the difference (in seconds) between times $timeDiff=$lastTime-$firstTime; //echo out the difference printf (Difference is %d seconds,$timeDiff); ? HTH Danny. - Original Message - From: Ron Allen [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, April 19, 2002 1:08 PM Subject: [PHP] Determine the difference between two dates If I have two variables of time both in the format of Y-m-j J:i:s How would I go about and get the difference? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Determine the difference between two dates
If I wanted to represent it in the format of Days,Hours,Minutes,Seconds how would that work Danny Shepherd [EMAIL PROTECTED] wrote in message 020e01c1e7a1$70098eb0$0200a8c0@dannys">news:020e01c1e7a1$70098eb0$0200a8c0@dannys... Firstly, I assume you mean Y-m-j H:i:s for the date format. To get the difference between 2 time strings : ?php // orginal time strings $firstTime=2002-04-19 13:49:00; $lastTime=2002-04-19 14:00:00; // convert to unix timestamps $firstTime=strtotime($firstTime); $lastTime=strtotime($lastTime); // perform subtraction to get the difference (in seconds) between times $timeDiff=$lastTime-$firstTime; //echo out the difference printf (Difference is %d seconds,$timeDiff); ? HTH Danny. - Original Message - From: Ron Allen [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, April 19, 2002 1:08 PM Subject: [PHP] Determine the difference between two dates If I have two variables of time both in the format of Y-m-j J:i:s How would I go about and get the difference? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Determine the difference between two dates
use the date() command (http://www.php.net/date) - using $timeDiff as the datestamp. HTH Danny - Original Message - From: Ron Allen [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, April 19, 2002 2:56 PM Subject: Re: [PHP] Determine the difference between two dates If I wanted to represent it in the format of Days,Hours,Minutes,Seconds how would that work Danny Shepherd [EMAIL PROTECTED] wrote in message 020e01c1e7a1$70098eb0$0200a8c0@dannys">news:020e01c1e7a1$70098eb0$0200a8c0@dannys... Firstly, I assume you mean Y-m-j H:i:s for the date format. To get the difference between 2 time strings : ?php // orginal time strings $firstTime=2002-04-19 13:49:00; $lastTime=2002-04-19 14:00:00; // convert to unix timestamps $firstTime=strtotime($firstTime); $lastTime=strtotime($lastTime); // perform subtraction to get the difference (in seconds) between times $timeDiff=$lastTime-$firstTime; //echo out the difference printf (Difference is %d seconds,$timeDiff); ? HTH Danny. - Original Message - From: Ron Allen [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, April 19, 2002 1:08 PM Subject: [PHP] Determine the difference between two dates If I have two variables of time both in the format of Y-m-j J:i:s How would I go about and get the difference? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Determine the difference between two dates
How is this going to give the overall time in difference... For instance A circuit went down at 17:30:45 it came back up at 18:37:49 what is the difference in time between the 2 in the format Days XX Hours XX Minutes XX Seconds XX Danny Shepherd [EMAIL PROTECTED] wrote in message 027601c1e7a9$fbe6f0f0$0200a8c0@dannys">news:027601c1e7a9$fbe6f0f0$0200a8c0@dannys... use the date() command (http://www.php.net/date) - using $timeDiff as the datestamp. HTH Danny - Original Message - From: Ron Allen [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, April 19, 2002 2:56 PM Subject: Re: [PHP] Determine the difference between two dates If I wanted to represent it in the format of Days,Hours,Minutes,Seconds how would that work Danny Shepherd [EMAIL PROTECTED] wrote in message 020e01c1e7a1$70098eb0$0200a8c0@dannys">news:020e01c1e7a1$70098eb0$0200a8c0@dannys... Firstly, I assume you mean Y-m-j H:i:s for the date format. To get the difference between 2 time strings : ?php // orginal time strings $firstTime=2002-04-19 13:49:00; $lastTime=2002-04-19 14:00:00; // convert to unix timestamps $firstTime=strtotime($firstTime); $lastTime=strtotime($lastTime); // perform subtraction to get the difference (in seconds) between times $timeDiff=$lastTime-$firstTime; //echo out the difference printf (Difference is %d seconds,$timeDiff); ? HTH Danny. - Original Message - From: Ron Allen [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, April 19, 2002 1:08 PM Subject: [PHP] Determine the difference between two dates If I have two variables of time both in the format of Y-m-j J:i:s How would I go about and get the difference? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Determine the difference between two dates
Appreciate the assistance Danny Figured it out $totaltime= date(H:i:s, mktime(0,0,$totaltime)); Just followed PHP from this page http://www.php.net/manual/en/function.mktime.php Ron Allen [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... How is this going to give the overall time in difference... For instance A circuit went down at 17:30:45 it came back up at 18:37:49 what is the difference in time between the 2 in the format Days XX Hours XX Minutes XX Seconds XX Danny Shepherd [EMAIL PROTECTED] wrote in message 027601c1e7a9$fbe6f0f0$0200a8c0@dannys">news:027601c1e7a9$fbe6f0f0$0200a8c0@dannys... use the date() command (http://www.php.net/date) - using $timeDiff as the datestamp. HTH Danny - Original Message - From: Ron Allen [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, April 19, 2002 2:56 PM Subject: Re: [PHP] Determine the difference between two dates If I wanted to represent it in the format of Days,Hours,Minutes,Seconds how would that work Danny Shepherd [EMAIL PROTECTED] wrote in message 020e01c1e7a1$70098eb0$0200a8c0@dannys">news:020e01c1e7a1$70098eb0$0200a8c0@dannys... Firstly, I assume you mean Y-m-j H:i:s for the date format. To get the difference between 2 time strings : ?php // orginal time strings $firstTime=2002-04-19 13:49:00; $lastTime=2002-04-19 14:00:00; // convert to unix timestamps $firstTime=strtotime($firstTime); $lastTime=strtotime($lastTime); // perform subtraction to get the difference (in seconds) between times $timeDiff=$lastTime-$firstTime; //echo out the difference printf (Difference is %d seconds,$timeDiff); ? HTH Danny. - Original Message - From: Ron Allen [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, April 19, 2002 1:08 PM Subject: [PHP] Determine the difference between two dates If I have two variables of time both in the format of Y-m-j J:i:s How would I go about and get the difference? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php