Langsung ke konten utama

Postingan

Menampilkan postingan dari Agustus, 2010

SQLSERVER - Lihat tanggal terakhir dari bulan

Few questions are always popular. They keep on coming up through email, comments or from co-workers. Finding Last Day of Any Month is similar question. I have received it many times and I enjoy answering it as well. I have answered this question twice before here: SQL SERVER – Script/Function to Find Last Day of Month SQL SERVER – Query to Find First and Last Day of Current Month Today, we will see the same solution again. Please use the method you find appropriate to your requirement. Following script demonstrates the script to find last day of previous, current and next month. ----Last Day of Previous Month SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0)) LastDay_PreviousMonth ----Last Day of Current Month SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0)) LastDay_CurrentMonth ----Last Day of Next Month SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+2,0)) LastDay_NextMonth ResultSet: LastDay_PreviousMonth ———————– 2007-07-31 23:59:59.000 LastDay_Current