【问题标题】:Calculate expiry date 3 months from now on MYSQL在MYSQL上计算从现在起3个月的到期日期
【发布时间】:2021-09-30 12:04:54
【问题描述】:

因此,我只获得了会员卡的到期日期,我需要查询以显示其卡将在当前系统日期未硬编码后 3 个月到期的所有客户。

假设今天是 2021 年 9 月 30 日,客户 1 的卡到期日期是 2021 年 12 月 12 日,客户 2 是 2021 年 10 月 18 日。因此查询将显示 customer1 的姓名,因为它的卡将在第 3 个月到期。

我尝试了几种不同的方法,但似乎找不到解决方案

从客户 c WHERE c.CardExpDate now() 中选择 DISTINCT c.customername 和
datediff(now(),c.CardExpDate)

【问题讨论】:

标签: mysql sql customer


【解决方案1】:

你可以试试这个

select c.*, timestampdiff(MONTH, now(3), CardExpDate) from customers c where
timestampdiff(MONTH, now(3), CardExpDate) = 3

【讨论】:

  • 谢谢,这很有魅力。得到了我想要的答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-16
  • 1970-01-01
  • 2021-02-22
  • 1970-01-01
  • 1970-01-01
  • 2011-08-03
相关资源
最近更新 更多