cancel
Showing results for 
Search instead for 
Did you mean: 

How can I get Year and Previous Month Name ?

dunncrew
Deputy Chef III
Deputy Chef III

I have a report that has data up to the end of previous calendar month. I want to email it, with the subject line saying "Report as of November 2024" 

I can get December 2024 with this:

=today.in_time_zone("America/New_York").strftime(" %B %Y ")

But can't figure out how to subtract 1 month from it  Where do I put "- 1.months"  without a syntax error ?

 

2 ACCEPTED SOLUTIONS

shivakumara
Executive Chef I
Executive Chef I

Hi @dunncrew ,
 As per the requirement you need always a month ago ( i.e. if current month December then requirement to get November). Please correct me.

in that case we can use directly "1.months.ago.in_time_zone("America/New_York").strftime(" %B %Y ")"   to simply the solution.

Thanks and Regards,
Shivakumar K A

View solution in original post

gary1
Executive Chef III
Executive Chef III

To stick with your current formula you can do this:

=(today - 1.months).in_time_zone("America/New_York").strftime(" %B %Y ")

View solution in original post

6 REPLIES 6

shivakumara
Executive Chef I
Executive Chef I

Hi @dunncrew ,
 As per the requirement you need always a month ago ( i.e. if current month December then requirement to get November). Please correct me.

in that case we can use directly "1.months.ago.in_time_zone("America/New_York").strftime(" %B %Y ")"   to simply the solution.

Thanks and Regards,
Shivakumar K A

gary1
Executive Chef III
Executive Chef III

To stick with your current formula you can do this:

=(today - 1.months).in_time_zone("America/New_York").strftime(" %B %Y ")

Hi @gary1 ,
Using (1.months.ago) instead of (today - 1.months) simplifies the solution. 

Thanks and Regards,
Shivakumar K A 

gary1
Executive Chef III
Executive Chef III

There's a difference between answering the question and providing the simplest solution. I answered the question.