krunal pande

krunal pande

  • NA
  • 101
  • 27.8k

how to select first 15 days and last 15 days of every month

Nov 7 2017 3:48 AM
Hi team,
 
how to select first 15 days  and last 15 days of every month of the year dynamically in sql server. 
 
e.g   
 
DECLARE @Month INTEGER
DECLARE @Year INTEGER
declare @midofmonth DATETIME
DECLARE @FirstDayOfMonth DATETIME
DECLARE @LastDayOfMonth DATETIME
DECLARE @16DayOfMonth DATETIME
DECLARE @Date1 datetime
SET @Year = YEAR(GETDATE())
SET @FirstDayOfMonth = dateadd(month, @month - 1, dateadd(year, @year - 1900, 0))
SET @Month = month(@FirstDayOfMonth)
SET @LastDayOfMonth = dateadd(month, @month, dateadd(year, @year - 1900, -1))
set @midofmonth=dateadd(month, 7, dateadd(year, @year - 1900, -17))
set @16DayOfMonth=Dateadd(d,16-DATEPART(d,getdate()),GETDATE())
 

Answers (1)