Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


find the date of the first day of the month

New Here ,
Sep 13, 2021 Sep 13, 2021

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

TOPICS
JavaScript

Views

41

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Sep 13, 2021 Sep 13, 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); }

Likes

Translate

Translate
Adobe Employee ,
Sep 13, 2021 Sep 13, 2021

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Sep 13, 2021 Sep 13, 2021

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Sep 13, 2021 Sep 13, 2021

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);
}

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 13, 2021 Sep 13, 2021

Copy link to clipboard

Copied

LATEST

Hi
Thank you very much. This is exactly the function I was looking for.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines