sql语句查询30内天到期数据,sql根据时间戳查询30天内到期的数据

 

 

SELECT
service_item.start_date,
service_item.end_date,
unix_timestamp(now()) as Today,
service_item.end_date-unix_timestamp(now()) as Subtracting,
round((service_item.end_date-unix_timestamp(now()))/86400) as due,


FROM
service_item

WHERE round((service_item.end_date-unix_timestamp(now()))/86400)>=0

获取当期(今天)的时间戳

unix_timestamp(now()) as Today,

到期时间戳减去当期时间戳
service_item.end_date-unix_timestamp(now()) as Subtracting,

期时间戳减去当期时间戳,除以86400(一天的时间的毫秒数),然后用sql round()函数四舍五入取整,得到到期天数
round((service_item.end_date-unix_timestamp(now()))/86400) as due,

 

延伸阅读:

 SQL取整函数round-四舍五入取整截取,FLOOR-向下取整截取,CEILING-向上取整截取

https://blog.csdn.net/cplvfx/article/details/84643532

MySQL通过sql语句获取当前日期|时间|时间戳

https://blog.csdn.net/cplvfx/article/details/84639437

sql查询小于6天的到期数据

https://blog.csdn.net/cplvfx/article/details/80339214

 

 

你可能感兴趣的:(sql)