我正在尝试编写一个 PHP 脚本,它将每月、每季度、每年等处理定期付款。该脚本将作为夜间 Cron 作业运行。
我不想遇到这样的情况:有人在 1 月 15 日订阅,然后在 2 月 1 日再次收费。
如果我根据 INTERVAL 1 MONTH 检查最后一笔付款,会发生什么情况?还是和INTERVAL 30 DAY一样,只在2月15日再处理一次付款,这就是我想要的?
最佳答案
根据MYSQL
If you add MONTH, YEAR_MONTH, or YEAR and the resulting date has a day that is larger than the maximum day for the new month, the day is adjusted to the maximum days in the new month:
mysql> SELECT DATE_ADD('2009-01-30', INTERVAL 1 MONTH); -> '2009-02-28' Date arithmetic operations require complete dates and do not work with incomplete dates such as '2006-07-00' or badly malformed dates:
因此,如果您使用 1 个月的内置函数,则不必担心该月的最后一天是什么时候。 MYSQL 为您完成所有工作。
关于mysql - 在 MySQL 日期间隔中,1 个月与 30 天相同吗? 1 QUARTER 和 3 MONTH 一样吗?等等?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7844671/