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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.