Jump to content

Recommended Posts

Hi I'm trying to use my countdown timer to do a certain action when time is reach in this example I want to point users to another page, but seems like I'm going wrong somewhere along the way. When it reaches 0 it just starts counting up from 0

<html>
<?php

define('TIMEZONE', 'Africa/Harare');
date_default_timezone_set(TIMEZONE);


$targetDate = new DateTime('2016-09-29 23:00:00');

$remaining = $targetDate->diff(new DateTime());

// not done
if( $remaining > 0 )
{ 
echo $remaining->format('%a D - %H:%I:%S');   //--> 86 D - 19:44:24
}

// done
else
{  
header("Location: testlogin.php");
			exit();



}
?>
</html>
Edited by cobusbo
Link to comment
https://forums.phpfreaks.com/topic/301135-countdown-timer-actions-not-working/
Share on other sites

So wouldn't that have been a good example to show us?

As requested I've tried something new with time()

<html>
<?php

define('TIMEZONE', 'Africa/Harare');
date_default_timezone_set(TIMEZONE);


$targetDate = new DateTime('2016-04-01 20:59:00');

$remaining = $targetDate->diff(new DateTime());
$now = time();
// not done
if( $now > $targetDate )
{ 
echo $remaining->format('%a D - %H:%I:%S');   //--> 86 D - 19:44:24
}

// done
else
{  
header("Location: testlogin.php");
			exit();



}
?>
</html>

Once again the failure to include simple PHP error checking during a development costs you time and frustration.

 

You are comparing a datetime var against an integer and that's what I get when I run your script:

 

Notice: Object of class DateInterval could not be converted to int in /home/albany/public_html/homejg/test.php on line 10

 

 

See my signature.

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.