RaelB RaelB - 5 months ago 10
PHP Question

Why does call to now() fail in php

Why does call to now() or current_timestamp() fail in simple php script?

<?php
try {
echo "Now: " . CURRENT_TIMESTAMP() . "<br>";
//echo "Time: " . time() . "<br>";

echo "Done";
}
catch(Exception $e) {
echo 'Message: ' .$e->getMessage();
}
?>


The script returns a blank page, and no error is reported. time() worked fine.

Answer

NOW() and CURRENT_TIMESTAMP() are MySQL functions, not PHP functions.

As this link suggests, the function you are looking for is date("Y-m-d H:i:s"). Here is the documentation