MySQL date_add

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的更多信息。

翻译自: https://davidwalsh.name/mysql-date-add

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值