last day of the current month?
i have to get开发者_运维问答 the last day of the current month. how can i get
SQLite (sqlite3)
Compute the last day of the current month.
SELECT date('now','start of month','+1 month','-1 day');
checkout this link as well if your using sqlite3 sqlite datetime functions
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.
SQLITE QUERY FOR CALCULATE NUMBER OF DAY IN A CURRENT MONTH
select strftime('%d',datetime('now','start of month','+1 month','-1 second'));
An alternative: add a month to the date, then subtract the resulting day value of the new month:
select day(dateAdd(d, -day(dateAdd(m,1,'2012-01-31')), dateAdd(m, 1, '2012-01-31')))
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
精彩评论