{"id":286,"date":"2007-06-14T16:34:27","date_gmt":"2007-06-14T15:34:27","guid":{"rendered":"http:\/\/www.galhano.com\/blog\/?p=286"},"modified":"2008-02-07T18:37:18","modified_gmt":"2008-02-07T17:37:18","slug":"examples-of-how-to-calculate-different-sql-server-dates","status":"publish","type":"post","link":"http:\/\/galhano.com\/blog\/?p=286","title":{"rendered":"Examples of how to Calculate Different SQL Server Dates"},"content":{"rendered":"<p><strong>First Day of Month<br \/>\n<\/strong>select DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)<br \/>\n<strong>Monday of the Current Week<br \/>\n<\/strong>select DATEADD(wk, DATEDIFF(wk,0,getdate()), 0)<\/p>\n<p><strong>set DATEFIRST 1<\/strong><\/p>\n<p>select DATEADD(dd, 1 &#8211; DATEPART(dw, getdate()), getdate())<\/p>\n<p><strong>First Day of the Year<\/strong><br \/>\nselect DATEADD(yy, DATEDIFF(yy,0,getdate()), 0)<br \/>\n<strong>First Day of the Quarter<\/strong><br \/>\nselect DATEADD(qq, DATEDIFF(qq,0,getdate()), 0)<br \/>\n<strong>Midnight for the Current Day<\/strong><br \/>\nSelect DATEADD(dd, DATEDIFF(dd,0,getdate()), 0)<br \/>\n<strong>Last Day of Prior Month<\/strong><br \/>\nselect dateadd(ms,-3,DATEADD(mm, DATEDIFF(mm,0,getdate()\u00c2  ), 0))<br \/>\n<strong>Last Day of Prior Year<br \/>\n<\/strong>select dateadd(ms,-3,DATEADD(yy, DATEDIFF(yy,0,getdate()\u00c2  ), 0))<br \/>\n<strong>Last Day of Current Month<\/strong><br \/>\nselect dateadd(ms,-3,DATEADD(mm, DATEDIFF(m,0,getdate()\u00c2  )+1, 0))<br \/>\n<strong>Last Day of Current Year<br \/>\n<\/strong>Select dateadd(ms,-3,DATEADD(yy, DATEDIFF(yy,0,getdate()\u00c2  )+1, 0))<br \/>\n<strong>First Monday of the Month<\/strong><br \/>\nselect DATEADD(wk, DATEDIFF(wk,0,<br \/>\n\u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2  dateadd(dd,6-datepart(day,getdate()),getdate())<br \/>\n\u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2  ), 0)\u00c2 \u00c2 \u00c2 \u00c2 \u00c2 <\/p>\n<p>\u00c2 <\/p>\n<p>\u00c2 <!--e9600da5633f26181bc65f9835694ddd--><\/p>\n","protected":false},"excerpt":{"rendered":"<p>First Day of Month select DATEADD(mm, DATEDIFF(mm,0,getdate()), 0) Monday of the Current Week select DATEADD(wk, DATEDIFF(wk,0,getdate()), 0) set DATEFIRST 1 select DATEADD(dd, 1 &#8211; DATEPART(dw, getdate()), getdate()) First Day of the Year select DATEADD(yy, DATEDIFF(yy,0,getdate()), 0) First Day of the Quarter select DATEADD(qq, DATEDIFF(qq,0,getdate()), 0) Midnight for the Current Day Select DATEADD(dd, DATEDIFF(dd,0,getdate()), 0) Last [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"close","ping_status":"close","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-286","post","type-post","status-publish","format-standard","hentry","category-sql-server","author-admin"],"_links":{"self":[{"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/286","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=286"}],"version-history":[{"count":0,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/286\/revisions"}],"wp:attachment":[{"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=286"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}