Mikey1980
Mikey1980

Reputation: 1001

MKTIME, PHP date/timestamp YYYY-MM-DD

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

Upvotes: 25

Views: 82731

Answers (4)

Sarfraz
Sarfraz

Reputation: 382726

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

Upvotes: 56

Joe Mills
Joe Mills

Reputation: 1619

The function I think you are looking for is

$datetime = strtotime($MySQLDateResponse);

$MySQLDatResponse being the date you get back from MySQL. This will give you a PHP time stamp. You can then convert that timestamp into any date format you want. For the one you listed it's

date("Y-m-d", $datetime);

Hope that helps

Upvotes: 0

Jon
Jon

Reputation: 437386

SELECT CURDATE();

Upvotes: 0

Mitch Dempsey
Mitch Dempsey

Reputation: 39899

date("Y-m-d") should give you the current date in that format.

Upvotes: 3

Related Questions