Hi,
Any funtion or method to find out the maximum day of the month?
i.e
if feb then 28
march then 31 and
april then 30
Please advise me,
rgds,
SouraHi
There are many previous posts that give you solutions see
http://tinyurl.com/r3ahf
John
"SouRa" wrote:
> Hi,
> Any funtion or method to find out the maximum day of the month?
> i.e
> if feb then 28
> march then 31 and
> april then 30
> Please advise me,
> rgds,
> Soura|||Hi
declare @.d datetime
set @.d='20060210'
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
"SouRa" <SouRa@.discussions.microsoft.com> wrote in message
news:8288A2E2-17F0-409F-BE8A-F65DBB818376@.microsoft.com...
> Hi,
> Any funtion or method to find out the maximum day of the month?
> i.e
> if feb then 28
> march then 31 and
> april then 30
> Please advise me,
> rgds,
> Soura|||Here is a sample script found on sqlservercentral.com written by AndrewP
which is very elegent:
DECLARE @.Month INT
DECLARE @.Year INT
DECLARE @.Date SMALLDATETIME
SET @.Month = 2
SET @.Year = 2012
SET DATEFORMAT ymd
SET @.Date = CAST(@.Year AS CHAR(4)) + '/' + RTRIM(CAST((@.Month) AS CHAR(2)))
+ '/01'
SET @.Date = DATEADD(m, 1, @.Date)
SELECT DAY(DATEADD(d, -1, @.Date))
"Uri Dimant" wrote:
> Hi
> declare @.d datetime
> set @.d='20060210'
> 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
>
> "SouRa" <SouRa@.discussions.microsoft.com> wrote in message
> news:8288A2E2-17F0-409F-BE8A-F65DBB818376@.microsoft.com...
>
>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment