THE LAST DAY OF MONTH

  • Do you have any idea how to find the last day of the previous month?

    The select I have below works, however I am more than sure that there shoud be another less complex way to do it.

    select datediff(day, convert(varchar(4),

    year(getdate())) + '/' +

    convert(varchar(25),(month(getdate()) -1)) + '/' +

    convert(varchar(25),day(getdate())) ,

    convert(varchar(4), year(getdate())) + '/' +

    convert(varchar(25),month(getdate()))+ '/' +

    convert(varchar(25),day(getdate())))

    Thank you,

    Liya

  • Try this:

    print Dateadd(day, -1 * (day(getdate())), getdate())

    Unless there's a system proc that does it, I think this is about as clean as you'll get.

  • Pretty good Jason - though I think if you want a rock solid EOM function, you'd want to eliminate the time portion, easily done though.

    Andy

  • quote:


    Try this:

    print Dateadd(day, -1 * (day(getdate())), getdate())

    Unless there's a system proc that does it, I think this is about as clean as you'll get.

    Jason,

    Wow!!! Well done, great job! Thank you very much.

    Liya


  • quote:


    Do you have any idea how to find the last day of the previous month?

    The select I have below works, however I am more than sure that there shoud be another less complex way to do it.

    select datediff(day, convert(varchar(4),

    year(getdate())) + '/' +

    convert(varchar(25),(month(getdate()) -1)) + '/' +

    convert(varchar(25),day(getdate())) ,

    convert(varchar(4), year(getdate())) + '/' +

    convert(varchar(25),month(getdate()))+ '/' +

    convert(varchar(25),day(getdate())))

    Thank you,

    Liya



    Yours SQL Friend

  • Just do this SQL-Statement.

    Select Convert(DateTime,Convert(Varchar(4),DatePart(YYYY, GetDATE()))

    +'/'+Convert(Varchar(2),DatePart(mm,GetDate()))+'/'+'01') - 1


    Yours SQL Friend

Viewing 6 posts - 1 through 5 (of 5 total)

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