Last Day of the Month

  • Given any date, how do you determine the last day of that month, Or how many days that month has?

    I know to do this in VB by using the DateSerial function but not in SQL.

    tnx

  • Following line returns the last day of the current month as a datetime

    DATEADD(day, -1,

    cast(MONTH(DATEADD(month,1,getdate())) as varchar)

    +'/01/'

    + cast(YEAR(DATEADD(month,1,getdate ())) as varchar)

    )

    First you calculate the first day of the next month, then you subtract one day.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply