0

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.

RaelB
  • 3,301
  • 5
  • 35
  • 55

2 Answers2

5

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

Community
  • 1
  • 1
Ulad Kasach
  • 11,558
  • 11
  • 61
  • 87
2

Your error should be something like

Call to undefined function CURRENT_TIMESTAMP()

CURRENT_TIMESTAMP is a synonym for CURRENT_TIMESTAMP() and NOW() and they are SQL functions, from what I know (maybe they also have meaning in other contexts).

As such, if that format is what you are looking for just do:

date("Y-m-d H:i:s");//like 2014-11-22 12:45:34

Also check this other SO question

Community
  • 1
  • 1
M.M
  • 2,254
  • 1
  • 20
  • 33