Jump to content

How to write php to check for a period of time?


four4swords

Recommended Posts

hi,

 

I got this bit of script here.. which writes down the time you did something...

 

<?php
$query_auto = "INSERT INTO timeplayground (dp_name, dp_time)
VALUE ('TIME: Auto NOW()', NOW() )";

mysql_query($query_auto) or die(mysql_error());
?>

 

But.. how would i script it so that php would check to see if 12 hours have gone past?

 

if(time passed >=12 hours){
Done waiting!
}else{
wait some more
}

 

Anyone get my drift? lol

here is my bit of code..

 

  $time = $row['TIME'];
   echo "time=$time&";

$timeneeded = mktime('0', '20', '0', '0', '0', '0');
$now = mktime();

if($now >($timeneeded+$time)){
echo 'yes!! Time is up!';
}else{
echo 'no!! Still gotta wait a bit!';
}

 

I'm trying to make a statement that.. will check to see if the required amount of waiting time has passed or now.. So.. First.. I've written a MySql query that has written the time they first started..

 

Then.. later when they run this php.. it should tell them if the required amount of waiting time has passed yet or not..

 

$timeneeded = mktime('0', '20', '0', '0', '0', '0');

This line of code is the time they need to wait.. so.. it's 20minutes here..

 

if($now >($timeneeded+$time)){

This bit here.. is saying... if the time now.. is greater than the "time you logged in plus the waiting time" then it should echo YES!

 

However! This isn't working!

 

The MySql writes the time in this format..  "2008-03-11 18:21:49"

While php writes in this format! .. "1205215154"

 

Which is really confusing!

 

lol Basically.. I just need a bit of code that will check if the waiting time has expired yet or not..

 

Anyone know how to write it?

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.