22 Votes

PHP: Error "Call to undefined function now()"

Question by Guest | 2016-07-24 at 17:52

I want to retrieve the current date using PHP and I have written the following code for that:

$d = now();

echo date("d.m.Y", $d));

However, I get the following error when running this lines:

Fatal error: 
Uncaught Error: Call to undefined function now()

What am I doing wrong? How can I fix this error? And how can I determine and get the current timestamp in PHP as variable?

ReplyPositiveNegative
1Best Answer7 Votes

The function now() is indeed available in some other programming languages, but not in PHP. There, for the same purpose, you can use the function time() instead:

$d = time();

echo date("d.m.Y", $d));

This code should output the current date.
2016-07-25 at 15:11

ReplyPositive Negative
Reply

Related Topics

PHP: Current Date and Time

Tutorial | 0 Comments

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.