Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NOW() function in PHP

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 
like image 362
MoeAmine Avatar asked Jan 03 '10 17:01

MoeAmine


People also ask

What is now function in PHP?

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.

What does NOW () return in PHP?

It is a PHP function that "returns the date & time in the same format as the MySQL function NOW()", which is precisely the question.

What is now () in MySQL?

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).

How can I get current date and time in PHP?

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.


1 Answers

You can use the date function:

date("Y-m-d H:i:s"); 
like image 197
troelskn Avatar answered Oct 10 '22 19:10

troelskn