Last day of a month?

Discussion in 'ASP General' started by Paulo, Jan 11, 2008.

  1. Paulo

    Paulo Guest

    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!
    Paulo, Jan 11, 2008
    #1
    1. Advertising

  2. 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.
    Bob Barrows [MVP], Jan 11, 2008
    #2
    1. Advertising

  3. Paulo

    Paulo Guest

    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:...
    > 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.
    >
    >
    Paulo, Jan 11, 2008
    #3
  4. 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.
    Bob Barrows [MVP], Jan 11, 2008
    #4
  5. Paulo

    Evertjan. Guest

    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)
    Evertjan., Jan 11, 2008
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    434
    Steve W. Jackson
    Dec 22, 2006
  2. LDOM - Last Day of Month

    , Feb 25, 2005, in forum: C Programming
    Replies:
    5
    Views:
    287
    Stan Milam
    Feb 26, 2005
  3. Mufasa
    Replies:
    0
    Views:
    386
    Mufasa
    Sep 5, 2008
  4. Andy
    Replies:
    1
    Views:
    682
  5. Rob Redmon

    Convert day of year to month, day

    Rob Redmon, Apr 4, 2008, in forum: Ruby
    Replies:
    7
    Views:
    280
    Alex Wayne
    Apr 4, 2008
Loading...

Share This Page