Results 1 to 12 of 12

Thread: Days in Month

  1. #1

    Thread Starter
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    Sure thing:

    Code:
    Public Function GetlastDayofMonth(pDate As Date)
        GetlastDayofMonth = Day(DateSerial(Year(Date), Month(Date) + 1, 0))
    End Function
    Usage: GetlastDayofMonth YourDate

    Example:
    Code:
    MsgBox "This year " & Format(Date, "mmmm") & " has " & GetlastDayofMonth(Date) & " days."

    Regards,

    ------------------

    Serge

    Software Developer
    [email protected]
    [email protected]




    [This message has been edited by Serge (edited 10-30-1999).]

  2. #2
    New Member
    Join Date
    Oct 1999
    Location
    Rotterdam, The Netherlands
    Posts
    2

    Post

    Yep, Serge's solution looks a lot better than mine (in the other post)....

  3. #3
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111

    Post

    how bout u answer my question serge? u seem hella good

  4. #4
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523

    Post

    THANKS

  5. #5
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523

    Post

    Is there a function to determine total number of days is any month?

    Thanks in advance

  6. #6

    Thread Starter
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    DiGiTaIErRoR, what IS your question then?


    Regards,

    ------------------

    Serge

    Software Developer
    [email protected]
    [email protected]



  7. #7
    New Member
    Join Date
    Nov 1999
    Posts
    1

    Post

    Is'nt it supposed to be like this ? (At least)

    Whats the point of sending something in to the function if you don't use it ??
    Whatever you send to this function it will return the current date's last day !!??

    Public Function GetlastDayofMonth(pDate As Date)
    GetlastDayofMonth = Day(DateSerial(Year(pDate), Month(pDate) + 1, 0))
    End Function

    /Zedar

  8. #8

    Thread Starter
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    The thing is: you have to pass atleast the Month and a Year so the date can be calculated correctly. (If that's your question)


    Regards,

    ------------------

    Serge

    Software Developer
    [email protected]
    [email protected]
    ICQ#: 51055819


  9. #9
    New Member
    Join Date
    Nov 1999
    Posts
    4

    Post

    zedar is right.

    The original code doesn't use the date variable passed to the function, but the Date function (thereby returning the number of days in the CURRENT month rather than the one in for the date specified).

    HTH,
    Tore.

  10. #10

    Thread Starter
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    I don't understand. In the example I made, I did passed the current date (just for testing), but the function itself is Generic. So you can pass any date.

    Regards,

    ------------------

    Serge

    Software Developer
    [email protected]
    [email protected]
    ICQ#: 51055819


  11. #11
    New Member
    Join Date
    Feb 2000
    Posts
    1

    Post

    Originally posted by Serge:
    Sure thing:

    Code:
    Public Function GetlastDayofMonth(pDate As Date)
        GetlastDayofMonth = Day(DateSerial(Year(Date), Month(Date) + 1, 0))
    End Function
    Usage: GetlastDayofMonth YourDate

    Example:
    Code:
    MsgBox "This year " & Format(Date, "mmmm") & " has " & GetlastDayofMonth(Date) & " days."

    Regards,
    Serge, thanks a lot this is really useful tip, the only thing is that in your function there should be pDate used instead of date in all your calculations.
    Public Function GetlastDayofMonth( _
    pDate As Date)
    GetlastDayofMonth = Day(DateSerial(Year(Date), Month(Date) + 1, 0))

  12. #12

    Thread Starter
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    Yep, I know I screwed up. That what happens when you type directly into the post (just a typo). LoL

    ------------------

    Serge

    Senior Programmer Analyst
    [email protected]
    [email protected]
    ICQ#: 51055819

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width