How can you find February's last day without hard-coding leap years?
Move to the start of the current month, then the next month, then back one day. SQLite applies these modifiers left to right.
SQLite example and interpretation
Starting from February 14 in 2024 yields the 29th. Adding a fixed thirty days from the middle of a month does not locate its boundary.
SELECT date('2024-02-14','start of month','+1 month','-1 day');Result [["2024-02-29"]]
中文
怎样获取闰年二月的最后一天而无需硬编码?
将日期移到当月首日,再移到下月首日,最后退一天即可得到当月末日。修饰符从左向右应用。
SQLite 示例与适用条件
以 2024 年 2 月 14 日为输入得到 29 日。先从月中加固定 30 天会失去月界语义。
SELECT date('2024-02-14','start of month','+1 month','-1 day');结果 [["2024-02-29"]]