• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

find the date of the first day of the month

Participant ,
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

513

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

Community Expert , 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);
}

Votes

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

Votes

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
Community Expert ,
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.

Votes

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
Community Expert ,
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);
}

Votes

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
Participant ,
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.

Votes

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