The last day of the current month?

I need to get the last day of the current month. How can I get

+3
source share
5 answers
set dateformat dmy

select dateadd(d, -1, dateadd(m, 1, '01-' + convert(varchar, month(getdate())) + '-' + convert(varchar, year(getdate()))))

add one month to the first of this month, minus one day.

+4
source

SQLite (sqlite3)

Calculate the last day of the current month.

SELECT date('now','start of month','+1 month','-1 day'); 

check this link if you use sqlite3 sqlite datetime functions

+5
source

SQLITE QUERY FOR CALCULATE NUMBER OF DAY FOR A MONTH

select strftime('%d',datetime('now','start of month','+1 month','-1 second'));
+1
source

Oracle

SELECT LAST_DAY(SYSDATE) AS Last_day_of_month FROM DUAL;

SQL Server

SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0)) AS Last_day_of_month 
0
source

Alternative: add the month to the date, and then subtract the total value of the day of the new month:

select day(dateAdd(d, -day(dateAdd(m,1,'2012-01-31')), dateAdd(m, 1, '2012-01-31')))

0
source

Source: https://habr.com/ru/post/1737978/


All Articles