Copy link to clipboard
Copied
Hi
I ask you if you can please help me to build a formula that allows me to find the first day of the month of a given date.
This formula allows me to find the first day of the current month.
var MonthFirstDay = new Date ();
MonthFirstDay.setDate (1);
event.value = util.printd ("mm / dd / yyyy", MonthFirstDay);
I would like to find the first day of the month of a certain date, for example the first day of the month relative to the date of 12/25/2021 is 12/01/2021
The approach is exactly the same. Create a Date object from the string (using the scand method of the util object), and then use the setDate method to change the date to 1.
Is the string coming from another field? If so, you can do it like this:
var s = this.getField("StartDate").valueAsString;
if (s=="") event.value = "";
else {
var d = util.scand("mm/dd/yyyy", s);
d.setDate(1);
event.value = util.printd("mm/dd/yyyy", d);
}
Copy link to clipboard
Copied
Hi there
Hope you are doing well and thank you for reaching out.
FOr more information about using Javascript please check the help page https://acrobatusers.com/tutorials/javascript_console/ and see if that helps.
Regards
Amal
Copy link to clipboard
Copied
@Amal. , you keep posting this canned reply, and I don't think it's very helpful, at least not in most cases. People who post questions about a specific issue of using JavaScript in Acrobat don't need a link to a generic page about how to use the JS Console. They want help with solving their problem. Sometimes they expect too much from us, in which case we provide resources on how they can learn to use Acrobat JS (like the one you provided), or offer professional help for hire, but often times (like in this case) the solution is just a couple of lines of code, which the experts here will generally provide.
Copy link to clipboard
Copied
The approach is exactly the same. Create a Date object from the string (using the scand method of the util object), and then use the setDate method to change the date to 1.
Is the string coming from another field? If so, you can do it like this:
var s = this.getField("StartDate").valueAsString;
if (s=="") event.value = "";
else {
var d = util.scand("mm/dd/yyyy", s);
d.setDate(1);
event.value = util.printd("mm/dd/yyyy", d);
}
Copy link to clipboard
Copied
Hi
Thank you very much. This is exactly the function I was looking for.