Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2003
    Posts
    311

    Unanswered: Get last day of month ??

    vb.net has something like

    month.lastday()

    i need to set a txtbox.value to the last day of the month,

    i can get the month :

    cstr(cint(month(now()))-1)

    is there a function or simple way to return 9/30/03 if i run the code today?

  2. #2
    Join Date
    Oct 2003
    Location
    Canada
    Posts
    574
    get the first day of the next month and subtract 1 day:

    dateadd("d",-1,dateadd("m",1,cdate(format(thedate,"yyyy/mm/") & "01"))

  3. #3
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    U can use next function to compute the days in a month, then add them to the beginning of your month -1


    Function DaysOfMonth(anyMonth As Byte) As Integer
    Dim anyDate As Date
    Dim nDays As Integer

    anyDate = DateSerial(Year(Date), anyMonth, 1)

    ' Adding one month to the given date then calculate the Difference
    between the two dates
    nDays = DateSerial(Year(anyDate), Month(anyDate) + 1, Day
    (anyDate)) _
    - DateSerial(Year(anyDate), Month(anyDate), Day(anyDate))
    DaysOfMonth = nDays
    End Function


Posting Permissions

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