I want to perform a simple query like this in my PHP,
SELECT noslots FROM calender WHERE coursedate = '01-01-2012';
however my dates are stored in the database in the standard YYYY-MM-DD format so obviously I get no reults.
I have tried reading through the manual but for a beginner it is difficult to extract the correct information
thank you for any help you can offer!
[=
You can use -
SELECT noslots
FROM calender
WHERE coursedate = STR_TO_DATE('01-01-2012', '%d-%m-%Y');
You might need to switch the %d and %m around depending on your date format.
MySQL's ONLY supported date/time format is yyyy-mm-dd hh:mm:ss
. You cannot pass any other string and have it properly parsed as a date. It is up to you to properly format your dates into the mysql format, meaning you'll have to pass 2012-01-01
in the query.
I would use PHP's date()
and strtotime()
functions:
mysql_query("SELECT `noslots` FROM `calender` WHERE `coursedate` = '" . date('Y-m-d H:i:s', strtotime('01-01-2012')) . "'");