Return Number of Days In a month.

Discussion in 'ASP General' started by Adam Knight, May 19, 2004.

  1. Adam Knight

    Adam Knight Guest

    I am wanting to create my own calendar asp module.

    Are there any functions in vbscript that return the number of days in a
    particular month depending on what year it is ??
     
    Adam Knight, May 19, 2004
    #1
    1. Advertising

  2. Adam Knight

    Ray at Guest

    You could do this:

    iDays = Day(DateAdd("d", -1, DateAdd("m", 1, yourDate)))

    If you don't have a value of "yourDate" and just have a month and a year,
    do:

    yourDate = yourYear & "-" & yourMonth & "-1"

    What the code above is doing is taking your date, adding one month to it,
    then subtracting one day.

    Ray at work


    "Adam Knight" <> wrote in message
    news:...
    > I am wanting to create my own calendar asp module.
    >
    > Are there any functions in vbscript that return the number of days in a
    > particular month depending on what year it is ??
    >
    >
     
    Ray at, May 19, 2004
    #2
    1. Advertising

  3. Adam Knight

    TomB Guest

    Ray,

    iDays = Day(DateAdd("d", -1, DateAdd("m", 1, yourDate)))

    DateAdd("m",1, yourDate) -- so it goes to June 19 (assuming yourDate is
    May19)
    DateAdd("d",-1,theAbove) -- so it goes to June 18
    Day(theAbove) -- 18

    Am I missing something?


    TomB


    "Ray at <%=sLocation%> [MVP]" <myfirstname at lane34 dot com> wrote in
    message news:...
    > You could do this:
    >
    > iDays = Day(DateAdd("d", -1, DateAdd("m", 1, yourDate)))
    >
    > If you don't have a value of "yourDate" and just have a month and a year,
    > do:
    >
    > yourDate = yourYear & "-" & yourMonth & "-1"
    >
    > What the code above is doing is taking your date, adding one month to it,
    > then subtracting one day.
    >
    > Ray at work
    >
    >
    > "Adam Knight" <> wrote in message
    > news:...
    > > I am wanting to create my own calendar asp module.
    > >
    > > Are there any functions in vbscript that return the number of days in a
    > > particular month depending on what year it is ??
    > >
    > >

    >
    >
     
    TomB, May 19, 2004
    #3
  4. Adam Knight

    Ray at Guest

    I was going with a "yourDate" as being the first of the month. If it's just
    an arbitrary date, then you (or Adam?) could do:

    myDate = "2004-05-19"
    yourDate = Year(myDate) & "-" & Month(myDate) & "-1"

    first. That will then do:
    - go to beginning of month
    - add one month
    - subtract one day

    Ray at work


    "TomB" <> wrote in message
    news:uI$%...
    > Ray,
    >
    > iDays = Day(DateAdd("d", -1, DateAdd("m", 1, yourDate)))
    >
    > DateAdd("m",1, yourDate) -- so it goes to June 19 (assuming yourDate is
    > May19)
    > DateAdd("d",-1,theAbove) -- so it goes to June 18
    > Day(theAbove) -- 18
    >
    > Am I missing something?
    >
    >
    > TomB
    >
    >
    > "Ray at <%=sLocation%> [MVP]" <myfirstname at lane34 dot com> wrote in
    > message news:...
    > > You could do this:
    > >
    > > iDays = Day(DateAdd("d", -1, DateAdd("m", 1, yourDate)))
    > >
    > > If you don't have a value of "yourDate" and just have a month and a

    year,
    > > do:
    > >
    > > yourDate = yourYear & "-" & yourMonth & "-1"
    > >
    > > What the code above is doing is taking your date, adding one month to

    it,
    > > then subtracting one day.
    > >
    > > Ray at work
    > >
    > >
    > > "Adam Knight" <> wrote in message
    > > news:...
    > > > I am wanting to create my own calendar asp module.
    > > >
    > > > Are there any functions in vbscript that return the number of days in

    a
    > > > particular month depending on what year it is ??
    > > >
    > > >

    > >
    > >

    >
    >
     
    Ray at, May 19, 2004
    #4
  5. Adam Knight

    dlbjr Guest

    Function GetDaysInMonth(dtmDate)
    If IsDate(dtmDate) Then
    dtmFirstOfMonth = DateSerial(Year(dtmDate),Month(dtmDate),1)
    GetDaysInMonth = Day(DateAdd("d",-1,DateAdd("m",1,dtmFirstOfMonth)))
    End If
    End Function

    'from dlbjr

    'Unambit from meager knowledge of inane others,engender uncharted sagacity.
     
    dlbjr, May 19, 2004
    #5
  6. "dlbjr" <> wrote in message
    news:eXRy$...
    > Function GetDaysInMonth(dtmDate)
    > If IsDate(dtmDate) Then
    > dtmFirstOfMonth = DateSerial(Year(dtmDate),Month(dtmDate),1)
    > GetDaysInMonth =

    Day(DateAdd("d",-1,DateAdd("m",1,dtmFirstOfMonth)))
    > End If
    > End Function
    >
    > 'from dlbjr
    >
    > 'Unambit from meager knowledge of inane others,engender uncharted

    sagacity.
    >
    >


    Day(DateSerial(Year(dtmDate),Month(dtmDate)+1,0))
     
    Chris Hohmann, May 19, 2004
    #6
    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. Bill
    Replies:
    10
    Views:
    745
    Fulvio
    Apr 13, 2006
  2. VYAS ASHISH M-NTB837

    RE: Convert month name to month number faster

    VYAS ASHISH M-NTB837, Jan 6, 2010, in forum: Python
    Replies:
    0
    Views:
    626
    VYAS ASHISH M-NTB837
    Jan 6, 2010
  3. Steven D'Aprano

    Re: Convert month name to month number faster

    Steven D'Aprano, Jan 6, 2010, in forum: Python
    Replies:
    0
    Views:
    495
    Steven D'Aprano
    Jan 6, 2010
  4. wrecker
    Replies:
    2
    Views:
    196
    Felbrigg
    Feb 5, 2004
  5. Shandy Nantz

    Getting number of days in a month

    Shandy Nantz, Feb 27, 2008, in forum: Ruby
    Replies:
    25
    Views:
    401
    Mohit Sindhwani
    Mar 1, 2008
Loading...

Share This Page