Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 month-end dates in quarter

Author  Topic 

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2013-01-28 : 05:57:42
Hi,

If I pass in a quarter-end i.e. 30 sep 2012, then I would like to get the month-end dates of each month in that quarter.

So for this example, it should return:
31 July 2012
31 Aug 2012
30 sep 2012

How is this done in sql please?
Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-01-28 : 06:14:22
[code]
DECLARE @date datetime

SET @date='20120930'

SELECT DATEADD(mm,N,DATEADD(qq,DATEDIFF(qq,0,@date),0))-1
FROM (SELECT 1 AS N
UNION ALL
SELECT 2
UNION ALL
SELECT 3
)t
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2013-01-28 : 06:26:54
Thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-01-28 : 06:34:00
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -