Jump to content

Time Comparison


hackalive

Recommended Posts

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

@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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.