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 2005 Forums
 Transact-SQL (2005)
 month days

Author  Topic 

waterduck
Aged Yak Warrior

982 Posts

Posted - 2010-05-13 : 02:02:41
hi all, any other shorter method to get month day?

Select day(dateadd(day, -1,dateadd(month, datediff(month, 0, '2010/04/01')+1,0)))


Hope can help...but advise to wait pros with confirmation...

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2010-05-13 : 03:13:12
Do you mean the number of days in a month?
select day(dateadd(month,datediff(month,-1,'2010/04/01'),-1))


CODO ERGO SUM
Go to Top of Page

waterduck
Aged Yak Warrior

982 Posts

Posted - 2010-05-13 : 03:23:11
thx mvj :)


Hope can help...but advise to wait pros with confirmation...
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-05-13 : 04:33:40
Another method


declare @d datetime
set @d='20100401'
select day(dateadd(month,1,@d-day(@d)+1)-1)


Madhivanan

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

- Advertisement -