This is how you get current date time in php:
$dateTime = new DateTime( "now", new DateTimeZone(date_default_timezone_get() ) );
$dt = $dateTime->format("Y-m-d H:i:s");
and this is how to compare it with a row in DB:
$q = "SELECT * FROM ht_chat_logs where TIMESTAMPDIFF(SECOND, time, '$dt') < 0 order by time asc";
it will return all the rows that were created after $dt.
==================================
And this is how you do it in JS:
var currentTime = new Date()
var last_activity = currentTime.getFullYear() + '_' + (currentTime.getMonth() + 1) + currentTime.getDate() + ' ' + currentTime.getHours() + ':' + currentTime.getMinutes() + ' ' + currentTime.getSeconds();
it's gonna return date time in the same format as the one we did in PHP and it's also the same format of mysql timestamp.
No comments:
Post a Comment