hackalive Posted December 30, 2010 Share Posted December 30, 2010 Hi guys I am looking for a loop which will run untill there is a difference of 10 minutes. The timestamp I wish to use is "ISO 8601 date (added in PHP 5)" [ date("c")] If anyone know some code for this it would be much appreicated. I can do the loop its just the comparison between the two timestamps as part of the loop I have no idea where to start on. Cheers, and thanks in advance. Link to comment https://forums.phpfreaks.com/topic/222969-time-comparison/ Share on other sites More sharing options...
trq Posted December 30, 2010 Share Posted December 30, 2010 http://php.net/manual/en/datetime.diff.php Link to comment https://forums.phpfreaks.com/topic/222969-time-comparison/#findComment-1152900 Share on other sites More sharing options...
hackalive Posted December 31, 2010 Author Share Posted December 31, 2010 @thrope: thanks This is the code date_default_timezone_set("Australia/Perth"); $datetimestamp1 = '2010-12-13T13:22:13+08:00'; $datetimestamp2 = date('c'); $interval = date_diff($datetimestamp1, $datetimestamp2); echo $interval->format('%i'); renders error: Warning: date_diff() expects parameter 1 to be DateTime, string given in J:\mowes_portable\www\update\index.php on line 16 Fatal error: Call to a member function format() on a non-object in J:\mowes_portable\www\update\index.php on line 17 Link to comment https://forums.phpfreaks.com/topic/222969-time-comparison/#findComment-1153261 Share on other sites More sharing options...
hackalive Posted January 5, 2011 Author Share Posted January 5, 2011 bump Link to comment https://forums.phpfreaks.com/topic/222969-time-comparison/#findComment-1154965 Share on other sites More sharing options...
johnny86 Posted January 5, 2011 Share Posted January 5, 2011 You need to create DateTime object for that function, here is an example I posted a while a go a little modifed: <?php // Create DateTime object with your timestamp $date = new DateTime("'2010-12-13 13:22:13', new DateTimeZone('Australia/Perth')); // Calculate the difference between your timestamp and "now" $interval = $date->diff(new DateTime()); // Get the data stored in the DateInterval echo $interval->format("Differernce is %d days, %h hours %i minutes and %s seconds."); ?> Link to comment https://forums.phpfreaks.com/topic/222969-time-comparison/#findComment-1154967 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.