Reputation: 1414
I'm managing a basketball website with a game schedule feature. In the database, there is a 'date' column in YYYY-mm-dd
format (2015-04-10
).
I want to feature in my homepage a box that shows games with the same dates years ago (2014-04-10
, 2010-04-10
, 1993-04-10
etc.).
Of course I can't use this query:
$date = date("Y-m-d");
$query = $db->query("SELECT * FROM `schedule` WHERE `date`='$date'");
Any ideas of how to do this?
Upvotes: 0
Views: 47
Reputation: 1269873
If you want the day and month to match, then use those functions in the where
clause:
where month(date) = month($date) and day(date) = day($date)
Note: it seems obligatory to recommend using parameters in the queries rather than inserting values directly in the query string.
Upvotes: 1