문제

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)
도움이 되었습니까?

해결책

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');
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top