Crystal Reports: Display Month Name and Year of Last Month [Field Notes]

less than 1 minute read | Suggest an edit | Issue? Question?


Buy Me A Coffee

Did this article help you?

I'd be grateful if you'd be willing to buy me a coffee.


Problem:

A report I’m running gets the data for the last Month. I’d like to nicely display the name of the month and year.

Solution

Step 1: Formula to Return the Date 1 Month Ago

Use the DateAdd function in the formula to get the date minus one month:

DateAdd("m", -1, CurrentDate)

This says to use “month” intervals, subtract one, and use the current date as the starting point.

Step 2: Display the Month Name and Year of the Date Formula

MonthName(Month({@DateMinusOneMonth})) + " " + ToText((Year({@DateMinusOneMonth})), 0, "")

This concatenates a string of the month name for the formula and the year for the formula. The part that calculates the year also notes that there should be no comma for thousands and no decimals (year here is being interpreted as just a number when outputted to ToText).


Buy Me A Coffee

Did this article help you?

I'd be grateful if you'd be willing to buy me a coffee.


Updated:

Leave a comment