last day of month | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

last day of month

How do I get the last day of the current month?

DECLARE @dt datetime
SELECT @dt = GETDATE()
SELECT DATEADD(MONTH, DATEDIFF(MONTH, 0, @dt), 30)

or
DECLARE @dt datetime
SELECT @dt = GETDATE()
SELECT DATEADD(MONTH, DATEDIFF(MONTH, 0, @dt)+1, -1)

or
if you need up to the last millisecond:
DECLARE @dt datetime
SELECT @dt = GETDATE()
SELECT DATEADD(ms, -3, DATEADD(MONTH, DATEDIFF(MONTH, 0, GetDate()) + 1, 0)) jg

]]>

Software Reviews | Book Reviews | FAQs | Tips | Articles | Performance Tuning | Audit | BI | Clustering | Developer | Reporting | DBA | ASP.NET Ado | Views tips | | Developer FAQs | Replication Tips | OS Tips | Misc Tips | Index Tuning Tips | Hints Tips | High Availability Tips | Hardware Tips | ETL Tips | Components Tips | Configuration Tips | App Dev Tips | OLAP Tips | Admin Tips | Software Reviews | Error | Clustering FAQs | Performance Tuning FAQs | DBA FAQs |