Get last day of previous month in yyyy-mm-dd format
问题 How do I get the last day of the previous month in yyyy-mm-dd format? This is what I have tried, however I don't want the seconds showing. Only YYYY-MM-DD: SELECT DATEADD(s, -1, DATEADD(mm, DATEDIFF(m, 0, GETDATE()), 0)) 回答1: Use the EOMONTH function along with FORMAT : SELECT FORMAT(EOMONTH(CURRENT_TIMESTAMP, -1), 'yyyy-MM-dd') The -1 in the above example means subtract 1 month from argument 1 (there is no need for DATEADD ). 回答2: Convert it into date only format SELECT convert(date,DATEADD