简体   繁体   中英

SELECT month day year as date in mysql?

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');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM