More Date Logic

declare @ThisDate datetime;

set @ThisDate = getdate();

select dateadd(dd, datediff(dd, 0, @ThisDate), 0) — Beginning of this day

select dateadd(dd, datediff(dd, 0, @ThisDate) + 1, 0) — Beginning of next day

select dateadd(dd, datediff(dd, 0, @ThisDate) – 1, 0) — Beginning of previous day

select dateadd(wk, datediff(wk, 0, @ThisDate), 0) — Beginning of this week (Monday)

select dateadd(wk, datediff(wk, 0, @ThisDate) + 1, 0) — Beginning of next week (Monday)

select dateadd(wk, datediff(wk, 0, @ThisDate) – 1, 0) — Beginning of previous week (Monday)

select dateadd(mm, datediff(mm, 0, @ThisDate), 0) — Beginning of this month

select dateadd(mm, datediff(mm, 0, @ThisDate) + 1, 0) — Beginning of next month

select dateadd(mm, datediff(mm, 0, @ThisDate) – 1, 0) — Beginning of previous month

select dateadd(qq, datediff(qq, 0, @ThisDate), 0) — Beginning of this quarter (Calendar)

select dateadd(qq, datediff(qq, 0, @ThisDate) + 1, 0) — Beginning of next quarter (Calendar)

select dateadd(qq, datediff(qq, 0, @ThisDate) – 1, 0) — Beginning of previous quarter (Calendar)

select dateadd(yy, datediff(yy, 0, @ThisDate), 0) — Beginning of this year

select dateadd(yy, datediff(yy, 0, @ThisDate) + 1, 0) — Beginning of next year

select dateadd(yy, datediff(yy, 0, @ThisDate) – 1, 0) — Beginning of previous year

About Vincent Stefanetti

Vincent Stefanetti Senior Consultant MAX Manufacturing Software Working with MAX and Related Technologies Since 1987 MAX ERP System Implementations and Projects MAX, Dynamics GP, Synergy, Event Manager, Crystal Reports, SQL Reporting Services, Database and System Migrations and Updates, MAX Training Classes - All Levels, Custom Reporting.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *