Jump to content

Trying to set a function to occur on specific date.


thewutwutwut
 Share

Recommended Posts

Hi all. So I'm working on this script and I'm using the mktime function that made a little countdown script. NOW my current goal is that when the countdown ends a new function occurs. Here's my tiny little script:

$target = mktime(0, 0, 0, 0, 0, 0) ;$today = time () ;$difference =($target-$today) ;$hours =(int) ($difference/3600) ;$minutes =(int) ($difference/1800) ;$seconds =(int) ($difference/900) ;print "Our event will occur in $hours hours, $minutes minutes, $seconds seconds" ;if ($today == $target) echo "SAMPLE1"; else echo "SAMPLE2";
I've edited out the proper target times for the sake of this post. Now CLEARLY I'm doing something wrong because whenever the time does equal the target it echoes "Sample 2". Can anyone help me out here?
Link to comment
Share on other sites

Hi all. So I'm working on this script and I'm using the mktime function that made a little countdown script. NOW my current goal is that when the countdown ends a new function occurs. Here's my tiny little script:I've edited out the proper target times for the sake of this post. Now CLEARLY I'm doing something wrong because whenever the time does equal the target it echoes "Sample 2". Can anyone help me out here?
try leaving only one "=" sign in the if statement. you use "==" only when dealing with strings (i think so).
Link to comment
Share on other sites

try leaving only one "=" sign in the if statement. you use "==" only when dealing with strings (i think so).
No, the "=" sign is always used for assignment, the "==" for equality testing. If he typed if ($today = $target) then $target would be stored to $today and the if statement would be true.Remember, UNIX timestamps record the time right down to the last second, and so even if you run the script one second late or early the times won't equate. Try echoing $today and $target, and see whether they really are the same.Your clock-time calculating part of the code is wrong. The unit of the UNIX timestamp is the second, and so it should look like this (using the floor function)
$hours = floor($difference/360);$minutes = floor($difference/60) - ($hours * 360);$seconds = $difference - ($hours * 360 + $minutes * 60);

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...