- 采用比较老的方法 FROM_UNIXTIME() 和 UNIX_TIMESTAMP()
SELECT
current_date() today,
(datediff(lastday, firstday) + 1) days
FROM
(
SELECT
CASE
WHEN MONTH(FROM_UNIXTIME(UNIX_TIMESTAMP(), 'yyyy-MM-dd')) IN (4, 6, 9, 11)
THEN date_add(
(FROM_UNIXTIME(UNIX_TIMESTAMP(), 'yyyy-MM-dd')),
30 - DAY(FROM_UNIXTIME(UNIX_TIMESTAMP(), 'yyyy-MM-dd'))
)
WHEN MONTH(FROM_UNIXTIME(UNIX_TIMESTAMP(), 'yyyy-MM-dd')) IN (1, 3, 5, 7, 8, 10, 12)
THEN date_add(
(FROM_UNIXTIME(UNIX_TIMESTAMP(), 'yyyy-MM-dd')