开发者

In mysql check the difference in selected date and current date

开发者 https://www.devze.com 2023-02-18 18:10 出处:网络
i have to check the selected date from date picker.if the selected date is ex:2010.01.22 within one year it echo free service or it ended one year it echo cost service.its check 开发者_如何学编程with

i have to check the selected date from date picker.if the selected date is ex:2010.01.22 within one year it echo free service or it ended one year it echo cost service.its check 开发者_如何学编程with current date .how to do in query


I think the answer is:

SELECT (DATEDIFF(date_field, NOW()) > 365) as year_expired;

Note: this query does not take leap years into account

Update: I found a better method

SELECT (DATE_ADD(date_field, INTERVAL 1 YEAR) < CURDATE()) AS year_expired;

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号