i have a timestamp problem. i would like to check a timestamp if that is in the past or future. if it is in the past, a query should happens.
up to this point i got a mysql-timestamp that will be fetched by
$row = $query->fetch_object();
$timestamp = $row->time
that contains:
2012-04-04 12:06:38
for further settings i use two more variables which will be:
$added = $timestamp + 1209600; //what adds 14days (1209600 seconds) to my db-timestamp
$check = $added < time(); //what checks if the 14days have passed or not
okay now if i test all of these with var_dump it will return for each:
string(19) "2012-04-04 12:06:38" at var_dump($timestamp)
int(1211612) at var_dump($added)
bool(true) at var_dump($check)
so my problem is, that the following query will be executed all the time, even in case of when the 14days should have been passed. i know that because i changed the timestamp to earlier date in january. here is my query:
if ($check === true){
$update = $db->query("UPDATE table SET xy='1' WHERE x='$x'");
}
something seems to be wrong and i have no clue what that might be.
I agree with barsju. The result from MySQL is a string of the DateTime entry and not actually a timestamp. Another option that would keep it within PHP is
strtotime($string);that will translate the string into its timestamp. All that matters is that you get a timestamp before your check.I would do it on this line of your example:
I believe there are also a couple other ways to get MySQL to return the timestamp instead as well.