根据日期列和条件从mysql表中选择数据

时间:2022-10-03 15:00:50

I have a column in mysql table PACKAGES as SERVICE_EXPIRY_DATE which holds a date time value.

我在mysql表PACKAGES中有一列作为SERVICE_EXPIRY_DATE,它包含一个日期时间值。

Now I want to match only those records whose SERVICE_EXPIRY_DATE is coming within the next 15 days from the moment of querying.

现在我想只匹配那些在查询之后的接下来的15天内发生SERVICE_EXPIRY_DATE的记录。

How can I match those columns.

我该如何匹配这些列。

1 个解决方案

#1


2  

You could do it by using intervals

您可以使用间隔来完成

WHERE `SERVICE_EXPIRY_DATE` BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 15 DAY)

Look at MySql documentation for more reference https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html

查看MySql文档以获取更多参考https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html

#1


2  

You could do it by using intervals

您可以使用间隔来完成

WHERE `SERVICE_EXPIRY_DATE` BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 15 DAY)

Look at MySql documentation for more reference https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html

查看MySql文档以获取更多参考https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html