Thursday, March 29, 2012

end of month

hello
what is the function that calculate the number of days in a given month ?
10xromy
I don't know such functions
Try this
declare @.d datetime
set @.d='20050110'
select datestring, case
when isdate(datestring/100*100+31) = 1 then 31
when isdate(datestring/100*100+30) = 1 then 30
when isdate(datestring/100*100+29) = 1 then 29
when isdate(datestring/100*100+28) = 1 then 28
end
from (
select convert(varchar,@.d,112) as datestring
) D
"romy" <romyedevelop@.hotmail.com> wrote in message
news:u3iwsVbGFHA.3284@.TK2MSFTNGP10.phx.gbl...
> hello
> what is the function that calculate the number of days in a given month ?
> 10x
>
>|||You can write your own user defined function that takes the month number or
month name as input parameter and returns the number of days in that month
using a CASE or an IF statement.
"romy" <romyedevelop@.hotmail.com> wrote in message
news:u3iwsVbGFHA.3284@.TK2MSFTNGP10.phx.gbl...
> hello
> what is the function that calculate the number of days in a given month ?
> 10x
>
>|||Try,
declare @.d datetime
set @.d = '20050215'
select datediff(day, convert(char(6), @.d, 112) + '01', dateadd(month, 1,
convert(char(6), @.d, 112) + '01'))
go
AMB
"romy" wrote:

> hello
> what is the function that calculate the number of days in a given month ?
> 10x
>
>
>|||romy,
"romy" <romyedevelop@.hotmail.com> wrote in message
news:u3iwsVbGFHA.3284@.TK2MSFTNGP10.phx.gbl...
> hello
> what is the function that calculate the number of days in a given month ?
> 10x
I use this:
declare @.d datetime
set @.d = '20050215'
select day(dateadd(ss, -1, dateadd(mm, datediff(m, 0, @.d) + 1, 0)))
Andrea|||DECLARE @.month INT
SET @.month=2
select day(CONVERT(Datetime, Convert(VARCHAR, (CASE WHEN @.month=12 THEN 0
Else @.month END +1)) + '/01/2005' ) -1)
"Andrea Benedetti" <abenedetti@.absistemi.it> wrote in message
news:OqHur9bGFHA.2748@.tk2msftngp13.phx.gbl...
> romy,
> "romy" <romyedevelop@.hotmail.com> wrote in message
> news:u3iwsVbGFHA.3284@.TK2MSFTNGP10.phx.gbl...
?
> I use this:
> declare @.d datetime
> set @.d = '20050215'
> select day(dateadd(ss, -1, dateadd(mm, datediff(m, 0, @.d) + 1, 0)))
> Andrea
>

No comments:

Post a Comment