Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Last day of a month?

Reply
Thread Tools

Last day of a month?

 
 
Paulo
Guest
Posts: n/a
 
      01-11-2008
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!


 
Reply With Quote
 
 
 
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      01-11-2008
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.


 
Reply With Quote
 
 
 
 
Paulo
Guest
Posts: n/a
 
      01-11-2008
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]" <(E-Mail Removed)> escreveu na mensagem
news:(E-Mail Removed)...
> 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.
>
>



 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      01-11-2008
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.


 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      01-11-2008
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)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Anyone using KDE 4.3 day to day? Lodi NZ Computing 17 10-05-2009 08:32 PM
Calendar yr-mnth-day data to day since data skorpio11@gmail.com Python 2 10-04-2009 12:54 AM
Now.day and day(now) returning the wrong day! Andy ASP .Net 1 11-06-2008 12:20 PM
Last Day! FA: DTS INDEPENDENCE DAY ld, Sealed DEEP RISING dvd J Rusnak DVD Video 0 03-05-2006 12:50 AM
Nice Day-Slow Day Collector»NZ NZ Computing 0 04-04-2005 10:18 PM



Advertisments