Skip to main content
Participant
April 12, 2021
Question

Dynamic Stamp - last month and year

  • April 12, 2021
  • 1 reply
  • 352 views

In a dynamic stamp, I want to print last month / year (mm / yyyy format).

I know this javascript to print current date : event.value = util.printd("dd/mm/yyyy", new Date());

 

What should I use to get last month + and year ?

If the stamp is used on april 12th 2021, I should get "03 / 2021".

If used on january 5th 2021, I should get "12 / 2020"

 

Thanks in advance for your help

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
April 13, 2021

You can use this code:

var d = new Date();
d.setDate(1);
d.setMonth(d.getMonth()-1);
event.value = util.printd("mm/yyyy", d);
Participant
April 13, 2021

Works perfectly, thanks a lot !