How can i get the name of the past month?

Hello i'm just trying to get the name of the past month, im using this code: 

proper(text(today(), "MMMM"))

But it only generates the name of the current month

Thanks!

  Discussion posts and replies are publicly visible

Parents
  • +1
    Certified Lead Developer

    Months are admittedly a little tricky to deal with using strictly OOB functionality.

    If you have the Date and Time Utilities plug-in installed (which there's no reason not to, IMHO), you could utilize the "subtractmonths()" function.

    text(subtractmonths(now(), 1), "MMMM")

    Edit: Ujjwal gives a good solution below Arrow down, using the OOB function "eomonth()".  An additional OOB-only approach would be to just use the month() function to get the month # you want, assemble a fake "date value" using that, and use that to produce the text() output desired:
     (edit2: this works fine for months other than January, so a manual check would need to be added to check for "0", though if anyone has a code-minimal trick for this then i'm curious!  i guess it's a good reason to use "subtractMonths()" or "eoMonth()" though.)

Reply
  • +1
    Certified Lead Developer

    Months are admittedly a little tricky to deal with using strictly OOB functionality.

    If you have the Date and Time Utilities plug-in installed (which there's no reason not to, IMHO), you could utilize the "subtractmonths()" function.

    text(subtractmonths(now(), 1), "MMMM")

    Edit: Ujjwal gives a good solution below Arrow down, using the OOB function "eomonth()".  An additional OOB-only approach would be to just use the month() function to get the month # you want, assemble a fake "date value" using that, and use that to produce the text() output desired:
     (edit2: this works fine for months other than January, so a manual check would need to be added to check for "0", though if anyone has a code-minimal trick for this then i'm curious!  i guess it's a good reason to use "subtractMonths()" or "eoMonth()" though.)

Children