Is there a PHP function that returns the date and time in the same format as the MySQL function NOW()
?
I know how to do it using date()
, but I am asking if there is a function only for this.
For example, to return:
2009-12-01 00:00:00
In PHP, now() function is used to get the current date and time. Now-a-days, the date and time function is used in place of the now() function. Both the date and time are the inbuilt functions in which the date function is used to format the date and time according to the user's specific requirements.
It is a PHP function that "returns the date & time in the same format as the MySQL function NOW()", which is precisely the question.
MySQL NOW() Function The NOW() function returns the current date and time. Note: The date and time is returned as "YYYY-MM-DD HH-MM-SS" (string) or as YYYYMMDDHHMMSS. uuuuuu (numeric).
Answer: Use the PHP date() Function You can simply use the PHP date() function to get the current data and time in various format, for example, date('d-m-y h:i:s') , date('d/m/y H:i:s') , and so on.
You can use the date function:
date("Y-m-d H:i:s");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With