Here's a quick MySQL tip I wanted to throw your way. I created an event system a while back and one of the requirements of the system was to show events that happened yesterday forward, meaning events older than 2 days were to be hidden. MySQL's date_add will allow you to do just that:
这是我想要的一条快速MySQL提示。 我不久前创建了一个事件系统,该系统的要求之一是显示昨天向前发生的事件,这意味着要隐藏2天以上的事件。 MySQL的date_add将允许您执行以下操作:
MySQL示例 (The MySQL Example)
SELECT title, venue, url, city, state, DATE_FORMAT(date_starts,\'%b %e\') as formatted_date
FROM events
WHERE date_starts >= DATE_ADD(NOW(), INTERVAL -1 DAY) // yesterday!
ORDER BY date_starts ASC
Note that I'm using a negative date value. You can use a positive date value to get tomorrow, next week, next month, etc..
请注意,我使用的是负日期值。 您可以使用正日期值获取明天,下周,下个月等。
I like the idea of showing events the from past few days -- they show that there's been action recently. Click here for more about MySQL date_add.
我喜欢过去几天显示事件的想法-它们表明最近有行动。 单击此处以获取有关MySQL date_add的更多信息。