Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MKTIME, PHP date/timestamp YYYY-MM-DD

Tags:

I need to query MySQL for the current date (from PHP) in YYYY-MM-DD format... anyone?

like image 776
Mikey1980 Avatar asked May 13 '10 17:05

Mikey1980


People also ask

How can I get current date in YYYY MM DD format in PHP?

$date = date("yyyy-mm-dd", strtotime(now));

What is Mktime PHP?

The mktime() function is an inbuilt function in PHP which is used to return the Unix timestamp for a date. The timestamp returns a long integer containing the number of seconds between the Unix Epoch (January 1, 1970, 00:00:00 GMT) and the time specified.

What is Unix timestamp in PHP?

Simply put, the Unix timestamp is a way to track time as a running total of seconds. This count starts at the Unix Epoch on January 1st, 1970 at UTC. Therefore, the Unix timestamp is merely the number of seconds between a particular date and the Unix Epoch.

How can we get second of the current time using date function?

PHP's time() returns a current Unix timestamp. With this, you can use the date() function to format it to your needs. the 2nd argument of the date function is assumed to be time() if left empty.


1 Answers

MySQL curdate:

You can do in query:

select curdate() 

PHP date

echo date('Y-m-d'); 

If you want to pass your own date format:

echo date('Y-m-d', strtotime($your_date)); 
like image 159
Sarfraz Avatar answered Sep 20 '22 17:09

Sarfraz