Reputation: 1895
Right now I have a MySQL table with one column called "date_time" that simply lists different DATETIME values (e.g. "2010-11-30 12:55:00"). Is it possible for me to construct a query that directly:
An abstract query in my mind would look like:
$query = "SELECT * FROM meetings WHERE uid = " . $_SESSION['uid'] . "AND the DATETIME month is active month AND the DATETIME day is bigger than the active day"
Is this functionality possible in MySQL (did some searching but didn't find anything helpful), or will I have to use PHP functions later to filter this stuff out? Many thanks in advance.
Upvotes: 3
Views: 2875
Reputation: 585
Something like:
$query = "SELECT * FROM meetings WHERE uid = " . $_SESSION['uid'] . "WHERE EXTRACT(month from now()) = extract(month from date_time) AND EXTRACT(day from now()) < extract(day from date_time)
Upvotes: 1
Reputation: 360572
MySQL has a ton of date formatting functions that would solve this for you:
Select by specific month...
SELECT ... WHERE MONTH(date_time) = MONTH(now());
Select by non-passed days:
SELECT ... WHERE DAY(date_time) > DAY(now());
Of course, these sorts of queries will pick out the same month/days in ANY records from ANY years. If you want to restrict to particular chunks of time, then you'll have to add more clauses.
Upvotes: 5