[英]Is there a way to get the First day of the previous month and Last day of current month?
這里我需要在 MySQL 中返回一個函數
上個月的開始日期
select date_format(curdate() - interval 1 month,'%Y-%m-01 00:00:00')
當月的最后一天
select date_format(last_day(curdate()),'%Y-%m-%d 23:59:59')
您將使用NOW()
獲取當前日期和時間。 MONTH()
獲取當前月份。 使用該值,您可以獲得上個月和下個月。 見http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html
當月的最后一天:
select last_day(now())
上個月的開始日期:
select adddate(subdate(last_day(now()), interval 2 month), 1)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.