Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here i am passing month and year so i want combined this month and year and i want get full date formate but the date should be last date of this month and year

SQL
DECLARE @Year INT = 2010, @Month INT = 08
SELECT CONVERT(DATE, CAST((@Year*100+@Month) AS VARCHAR(6))+'01') AS [YYYY-MM-DD]


but above query show only first date of month and year. but i want last date of what ever i am passing month and year
please any one can help me
Posted

1 solution

try this:

C#
DECLARE @Year INT = 2011, @Month INT = 2
DECLARE @dtDate DATETIME
set @dtDate= CONVERT(DATE, CAST((@Year*100+@Month) AS VARCHAR(6))+'01') 
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@dtDate)+1,0))LastDay_AnyMonth
 
Share this answer
 
Comments
Member 10562086 4-Apr-14 5:45am    
thank you its working
King Fisher 4-Apr-14 5:58am    
you 're welcome ;)

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