Forum Discussion

aaronb's avatar
aaronb
New Contributor
7 years ago

Expression - Last Day of the Month

Hi,

I was wondering if anyone had an expression they should share to calculate last day of the month. Any help is greatly appreciated!

6 Replies

  • Anil's avatar
    Anil
    New Contributor III

    We can also use the following expression.

    Date.UTC(Date.now().getFullYear(), Date.now().plusDays(1).getMonth(), 0, 0, 0, 0, 0)

  • aleung's avatar
    aleung
    Contributor III

    Here is an example of last day of this month. You can revise it to fit your needs.

    Date.parse(Date.now().plusMonths(1).getFullYear()+“-”+Date.now().plusMonths(1).getMonth()+“-”+“01”).minusDays(1)

    • tstack's avatar
      tstack
      Former Employee

      Note that you can avoid the string manipulation and use the withDayOfMonth() method to replace the current day with 1, like so:

      Date.now().plusMonths(1).withDayOfMonth(1).minusDays(1)
      
      • aleung's avatar
        aleung
        Contributor III

        Thanks, Tim! Learn something new every day.

    • aaronb's avatar
      aaronb
      New Contributor

      Alan,

      That works great. Thank you