Skip to main content
mariov0002
October 5, 2022
Solved

How can i get the name of the past month?

  • October 5, 2022
  • 5 replies
  • 0 views

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!

Best answer by mikes0011

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 [emoticon:69e2b8567aa9403dab9ec1f7e93b79cf], 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.)

5 replies

mikes0011
mikes0011Answer
Brainy
October 5, 2022

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 [emoticon:69e2b8567aa9403dab9ec1f7e93b79cf], 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.)

The Expression Guru
mariov0002
October 5, 2022

Thanks a lot!

Participating Frequently
October 5, 2022

Hi we can use eomonth() function

 

text(
  eomonth(
    now(),
    -1
  ),
  "MMMM"
)

mariov0002
October 5, 2022

Thanks a lot!

December 8, 2022

text(
a!subtractDateTime( startDateTime: today(), months: 1),
"mmmm"
)