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)
 Finding Date

Author  Topic 

amitranjan
Starting Member

45 Posts

Posted - 2010-05-17 : 10:58:04
I need the logic below to retrieve end date from a given date
Enddate is the date closest to the 15th or last day of the month which is not greater than the startdate

Example If the startdate is between 3/1/10 and 3/15/10 then the enddate would be 3/15/10, if the date is between 3/16/10 and 3/31/10 then the end date is 3/31/10


amit Ranjan

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-05-17 : 11:16:59


declare @d datetime
set @d=getdate()
If day(@d)>15
select dateadd(month,datediff(month,0,@d)+1,-1)
else
select dateadd(month,datediff(month,0,@d),14)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -