Last day of a month?

P

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!
 
B

Bob Barrows [MVP]

Paulo said:
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.
 
P

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!
 
B

Bob Barrows [MVP]

Paulo said:
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.
 
E

Evertjan.

Bob Barrows [MVP] wrote on 11 jan 2008 in
microsoft.public.inetserver.asp.general:
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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top