Last day of a month?

Last day of a month?

am 11.01.2008 18:57:01 von PaulO

If I keep a hard sql statment to show all records from 1 to 31 of each month
will get error on months where there are no 31 days, how can i know the last
day of the month ? any sql function or just via programming language? Using
ASP and Sql Server 2005!

What you suggest ?

Thanks!

Re: Last day of a month?

am 11.01.2008 19:11:40 von reb01501

Paulo wrote:
> If I keep a hard sql statment to show all records from 1 to 31 of
> each month will get error on months where there are no 31 days,

Huh? What error? Show us the relevant part of the sql statement, i.e.,
whatever is left after you prune out everything that is not required to
demonstrate the problem

> how
> can i know the last day of the month ? any sql function or just via
> programming language? Using ASP and Sql Server 2005!
>
There are so many ways to answer this (vbscript, javascript, T-SQL) that
I am not even going to try without further details about what you are
doing. I don't want to see your entire page - just the part where the
error occurs.

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Re: Last day of a month?

am 11.01.2008 19:39:49 von PaulO

Thanks Bob, I found a function on our best friend Google!

Mes=month with 2 digits / Ano=year with 4 digits

Private Function GetMonthEnd(Mes,Ano)
GetMonthEnd = Day(DateAdd("d", -1, DateAdd("m", 1, ((Ano & "/" & Mes &
"/01")))))
End Function

so on asp sql statment would be:

" AND (DATA_HORAS BETWEEN '" & ano & mes & "01' AND '" & _
ano & mes & GetMonthEnd(Mes,Ano) & "')"

Bye man!

"Bob Barrows [MVP]" escreveu na mensagem
news:u3LPr1HVIHA.3440@TK2MSFTNGP04.phx.gbl...
> Paulo wrote:
>> If I keep a hard sql statment to show all records from 1 to 31 of
>> each month will get error on months where there are no 31 days,
>
> Huh? What error? Show us the relevant part of the sql statement, i.e.,
> whatever is left after you prune out everything that is not required to
> demonstrate the problem
>
>> how
>> can i know the last day of the month ? any sql function or just via
>> programming language? Using ASP and Sql Server 2005!
>>
> There are so many ways to answer this (vbscript, javascript, T-SQL) that
> I am not even going to try without further details about what you are
> doing. I don't want to see your entire page - just the part where the
> error occurs.
>
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will get a
> quicker response by posting to the newsgroup.
>
>

Re: Last day of a month?

am 11.01.2008 20:04:00 von reb01501

Paulo wrote:
> Thanks Bob, I found a function on our best friend Google!
>
> Mes=month with 2 digits / Ano=year with 4 digits
>
> Private Function GetMonthEnd(Mes,Ano)
> GetMonthEnd = Day(DateAdd("d", -1, DateAdd("m", 1, ((Ano & "/" & Mes
> & "/01")))))
> End Function
>
> so on asp sql statment would be:
>
> " AND (DATA_HORAS BETWEEN '" & ano & mes & "01' AND '" & _
> ano & mes & GetMonthEnd(Mes,Ano) & "')"
>

I'm glad you're happy with it, but it's not the way I would do it.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Re: Last day of a month?

am 11.01.2008 20:24:45 von exjxw.hannivoort

Bob Barrows [MVP] wrote on 11 jan 2008 in
microsoft.public.inetserver.asp.general:

> Paulo wrote:
>> If I keep a hard sql statment to show all records from 1 to 31 of
>> each month will get error on months where there are no 31 days,
>
> Huh? What error? Show us the relevant part of the sql statement, i.e.,
> whatever is left after you prune out everything that is not required
> to demonstrate the problem
>
>> how
>> can i know the last day of the month ? any sql function or just via
>> programming language? Using ASP and Sql Server 2005!
>>
> There are so many ways to answer this (vbscript, javascript, T-SQL)
> that I am not even going to try without further details about what you
> are doing. I don't want to see your entire page - just the part where
> the error occurs.

javascript:

function lastDay(y,m) { // jan=1,Dec=12
return new Date(y,m,0).getDate();
};

var d = lastDay(2008,2); // will set d equal to 29


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)