Frage

Using a mysql database, I want to select only ContentObject ids from today forward (content objects associated with current and future events). But I'm not sure how to select the month, day, and year from the Events table as a date to compare with today's date. Can someone show me how to do this? Thanks!

I'm going to be using this sql from a php script, so if it's easier to do some work in php, that's fine, too.

Schema:
Events Table:
id |int(11)
attribute_id |int(11)
month |tinyint(4)
day |tinyint(4)
year |int(11)

Attributes Table:
id |int(11)
content_id |int(11)

ContentObject Table:
id |int(11)

Figured it out: This got me what I was looking for:

select E.id, E.year, E.month, E.day
from Events as E
where (E.year*10000 + E.month*100 + E.day) >= (CURDATE() + 0)
War es hilfreich?

Lösung

The best way is to add date filters into the SQL treatments... In SQL you have a lot of date function

See MySQL doc here to retrieve month, year, or whatever you wan't... Example for months :

SELECT * FROM mytable WHERE column_month = DATE_FORMAT(CURRENT_DATE, '%c');
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top