Why is the timestamp generated by the PHP time() function so different from SQL datetime?
If I do a date('Y-m-d', time()); in PHP, it gives me the time now, as it should. If I just take the time() portion and do:
$now = time();
//then execute this statement 'SELECT * FROM `reservation` WHERE created_at < $now'
I get nothing. But hey, so if the value of $now was 1273959833 and I queried
'SELECT * FROM `reservation` WHERE created_at < 127395983300000000'
then I see the records that I have created. I think one is tracked in microseconds vs the other is in seconds, but I can’t find any documentation on this! What would be the right conversion between these two?
The
time()function doesn’t return microseconds, so it should work if you’re using the correct datatype. But you have 2 different datatypes right now,INTand a date field (could beDATE/DATETIME/TIMESTAMP). If you want to compare a date in the database to a timestamp as integer, you could use something like: