{"id":39,"date":"2008-03-28T09:18:25","date_gmt":"2008-03-28T15:18:25","guid":{"rendered":"https:\/\/jackdonnell.com\/?p=39"},"modified":"2008-03-28T11:46:15","modified_gmt":"2008-03-28T17:46:15","slug":"t-sql-create-a-last-full-month-and-current-month-view","status":"publish","type":"post","link":"https:\/\/jackdonnell.com\/?p=39","title":{"rendered":"T-SQL Create a View for Report Date Ranges by Month"},"content":{"rendered":"<p>The below example gives prior and current month first and last day values.The code below dynamically formats the date to give you date range values for reporting:<\/p>\n<blockquote><p>\n[LFM-FirstDay] &#8211; First Day of thePrior Month or Last Full Month First Day,<br \/>\n[LFM-LastDay] &#8211; 11:59 PM of the last day of the prior month,<br \/>\n[CM-FirstDay] &#8211; Current Month First Day and<br \/>\n[CM-LastDay] &#8211; 11:59 PM of the last day of the Current month.<\/p><\/blockquote>\n<p><code>USE [dbofchoice]<br \/>\nGO<br \/>\nSET ANSI_NULLS ON<br \/>\nGO<br \/>\nSET QUOTED_IDENTIFIER ON<br \/>\nGO<br \/>\nCREATE VIEW [DBO].[ReportDates]<br \/>\nAS<br \/>\n\/*<br \/>\nLFM = LAST FULL MONTH<br \/>\nCM = CURRENT MONTH<br \/>\n*\/<br \/>\nSELECT<br \/>\nDATEADD(month, -1 ,DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0))<br \/>\nas [LFM-FirstDay]<br \/>\n,DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate()),0))<br \/>\nas [LFM-LastDay]<br \/>\n,DATEADD(mm, DATEDIFF(m,0,getdate()),0)<br \/>\nas [CM-FirstDay]<br \/>\n,DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())+1,0))<br \/>\nas [CM-LastDay]<br \/>\nGO<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The below example gives prior and current month first and last day values.The code below dynamically formats the date to give you date range values for reporting: [LFM-FirstDay] &#8211; First Day of thePrior Month or Last Full Month First Day, &hellip;<\/p>\n<p class=\"read-more\"><a href=\"https:\/\/jackdonnell.com\/?p=39\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[138,113,5],"tags":[115,150,151,291],"class_list":["post-39","post","type-post","status-publish","format-standard","hentry","category-programming","category-reportingbi","category-t-sql","tag-bi","tag-dates","tag-reporting","tag-t-sql"],"_links":{"self":[{"href":"https:\/\/jackdonnell.com\/index.php?rest_route=\/wp\/v2\/posts\/39","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jackdonnell.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jackdonnell.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jackdonnell.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jackdonnell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=39"}],"version-history":[{"count":0,"href":"https:\/\/jackdonnell.com\/index.php?rest_route=\/wp\/v2\/posts\/39\/revisions"}],"wp:attachment":[{"href":"https:\/\/jackdonnell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=39"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jackdonnell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=39"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jackdonnell.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=39"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}