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

Date field and day field. Day field is not accurate...Help!

New Here ,
Jun 28, 2017 Jun 28, 2017

Copy link to clipboard

Copied

Hi guys, I'm currently using the following script for my day

// get the date from the "Date1"
var d = new Date(this.getField("Date1").value);
if (!isNaN(d.getDay()))
{
switch (d.getDay())
{
case 0:
event.value = "Sun";
break;
case 1:
event.value = "Mon";
break;
case 2:
event.value = "Tue";
break;
case 3:
event.value = "Wed";
break;
case 4:
event.value = "Thu";
break;
case 5:
event.value = "Fri";
break;
case 6:
event.value = "Sat";
break;
default:
event.value = "";
}
}
else
{
event.value = "";

}

My problem here is that for exemple.. today the 28th says TUESDAY not Wednesday... I'm extremely confused. Any ideas?

TOPICS
Acrobat SDK and JavaScript , Windows

Views

337

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 , Jun 28, 2017 Jun 28, 2017

Assuming the value of your field is a string, you need to parse it into a Date object using something like the code below. Adjust for the format of your date string.

var d= util.scand("mm/dd/yyyy", this.getField("Date1").value);

Votes

Translate

Translate
Community Expert ,
Jun 28, 2017 Jun 28, 2017

Copy link to clipboard

Copied

Assuming the value of your field is a string, you need to parse it into a Date object using something like the code below. Adjust for the format of your date string.

var d= util.scand("mm/dd/yyyy", this.getField("Date1").value);

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
New Here ,
Jun 28, 2017 Jun 28, 2017

Copy link to clipboard

Copied

LATEST

Thanks guys finaly got this working!!! Im in no way a java scripter so this helped tremendously.

Again thank you!

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
LEGEND ,
Jun 28, 2017 Jun 28, 2017

Copy link to clipboard

Copied

I would set my entry date field format to one of the standard date formats and use the util.scand method as mentioned to create a date object. You can then simplify your code by using the util.printd method to format the 3 character day of the week from the date object.

Your script with error detection could be:

// get the date from the "Date1"

var oDateField = this.getField("Date1");

if(oDateField == null) {

app.alert("Error accessing Date1 field", 0,1, "Field Error");

} else {

if(oDateField.valueAsString == ""){

  event.value = "";

} else {

   var oDate = util.scand("dd-mmm-yyyy", oDateField.valueAsString);

  if(oDate == null) {

   app.alert("Date conversion error " + oDateField.valueAsStirng, 0,1, "Date Conversion Error");

  } else {

   event.value = util.printd("ddd", oDate);

  } // end date object null;

} // end field value not null;

} // end date field not null;

This code catches bad field names and incorrect date strings. You will need to adjust the date format for the util.scand method to match the input field's date format.

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