Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I will give only Month and year in SQL,I need start Date to End Date month of year

For Example

I will give SQl Month '05' Year '2014'

I Need Start Start to End Date for this month


01-05-2014 to 31-05-2014


pls help me
Posted

SQL
DECLARE @Month int
DECLARE @Year int

set @Month = your Month 
set @Year = your Year

select DATEADD(month,@Month-1,DATEADD(year,@Year-1900,0))

select DATEADD(day,-1,DATEADD(month,@Month,DATEADD(year,@Year-1900,0)))
 
Share this answer
 
v2
SQL
DECLARE @Month int
DECLARE @Year int
Declare @TempStartDate Datetime, @TempEndDate Datetime

set @Month = 5
set @Year = 2014

select  @TempStartDate=  DATEADD(month,@Month-1,DATEADD(year,@Year-1900,0)) 


select @TempEndDate= DATEADD(day,-1,DATEADD(month,@Month,DATEADD(year,@Year-1900,0))) 

SELECT [Date] = DATEADD(Day,Number,@TempStartDate) 
FROM  master..spt_values 
WHERE Type='P'
AND DATEADD(day,Number,@TempStartDate) <= @TempEndDate


If you got exactly what you want then click accept solution.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900