25

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

Mikey1980
  • 971
  • 4
  • 15
  • 24
  • 1
    *(reference)* Date and Time Functions in MySql: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_curdate and PHP Date Function: http://de.php.net/manual/en/function.date.php – Gordon May 13 '10 at 18:12

4 Answers4

56

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));
Flimm
  • 136,138
  • 45
  • 251
  • 267
Sarfraz
  • 377,238
  • 77
  • 533
  • 578
3

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

Mitch Dempsey
  • 38,725
  • 6
  • 68
  • 74
0

SELECT CURDATE();

Jon
  • 428,835
  • 81
  • 738
  • 806
0

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

Joe Mills
  • 1,619
  • 11
  • 12