Free Web Hosting Forum
Go Back   Free Web Hosting Forum > Website Building > Web Programming
Reload this Page Best way to calculate the number of seconds between two date/times
Reply
 
Thread Tools Display Modes
(#1 (permalink))
Old
Junior Member
pcroarkin is on a distinguished road
 
Posts: 3
Join Date: Jun 2012
Default Best way to calculate the number of seconds between two date/times - 06-01-2012, 10:21 PM

I am looking for suggestions on the best way to calculate the number of seconds between two dates and times. Any suggestions? Seems like strtotime() would do the trick but wondering if anyone has any other preferred methods.
Reply With Quote
Sponsored Links
(#2 (permalink))
Old
dx4's Avatar
dx4 dx4 is offline
Member
dx4 is on a distinguished road
 
Posts: 95
Join Date: Mar 2012
Send a message via Skype™ to dx4
Default 06-03-2012, 11:00 PM

If you want to do it yourself, it's simple math. Subtrack the seconds, the minutes, the hours.... given and then multiply the minutes with 60, hours with 3600 and so on.


And when everything else fail, try reading the manual.
Reply With Quote
(#3 (permalink))
Old
Leder678's Avatar
Senior Member
Leder678 is on a distinguished road
 
Posts: 1,618
Join Date: Jan 2009
Location: Norway
Send a message via MSN to Leder678
Default 06-04-2012, 05:58 AM

http://php.net/manual/en/function.strtotime.php


Follow me on twitter @Mortenrb

W3Fools - Read and learn

Please AT LEAST read the 10 bolded lines of the TOS at:
http://www.000webhost.com/includes/tos.php
Reply With Quote
(#4 (permalink))
Old
Senior Member
grace1004 is on a distinguished road
 
Posts: 762
Join Date: Dec 2010
Default 06-04-2012, 06:39 AM

You can calculate it with mktime() function, which converts datetime into unix timestamp (expressed as seconds).
The following is an example:

PHP Code:
<?php
//$time = mktime($hour, $minute, $second, $month, $day, $year);

$time mktime(133050622012); 
$time_2 mktime(152740642012);

$diff $time_2 $time;

echo 
$diff;
?>

Last edited by grace1004; 06-04-2012 at 07:36 AM.
Reply With Quote
Reply

Thread Tools
Display Modes

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 Off
Pingbacks are Off
Refbacks are Off




Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.5.2
vBulletin Skin developed by: vBStyles.com