Skip to main content
Inspiring
April 22, 2020
解決済み

Get the day of the week from a date field

  • April 22, 2020
  • 返信数 1.
  • 4604 ビュー

I have a date field that is formatted as "mm/dd".  This field is named "DATE1".

I would like to have another field that looks at DATE1 and returns the day of the week of DATE1.  The output of the field would be Sun, Mon, Tue, Wed, Thu, Fri, or Sat.

I have tried to use this code, but I have not had any luck...

 

// 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 = "O"; // we don't have a valid day
}
}
else
{
event.value = "P";

}

If there is an easier solution I am all for that too. (Adobe Acrobat Pro DC)

Thanks for your help.

このトピックへの返信は締め切られました。
解決に役立った回答 JMC08

Is there any solution where the year does not have to be displayed?  The field is not big enough to display the year.

 

I will work on this as well and see if I can find a solution.  

 

Thanks for your help.


When I use the following script I can get the date format to change from "m/d" to "m/d/yy".

var date= util.scand("mm-dd", this.getField("DATE1").value);
date.setDate(date.getDate())
if (this.getField("DATE1").value!="")
{
event.value=util.printd("mm/dd/yy",date)
}
else
{event.value=""}

 

I cannot get the script originally sugested to work to convert this to the "ddd" format.  This is the case even if the orginal field has the year in the format.

 

返信数 1

Bernd Alheit
Community Expert
Community Expert
April 22, 2020
JMC08作成者
Inspiring
April 22, 2020

Thank you, but I can not get that to work either...

I used the field name as "DATE1" and DATE, both with the same unsatifactory result (no result).  

var s = this.getField("Date1").valueAsString;

event.value = "";

if (s!="") {

var d = util.scand("m/dd/yy", s);

if (d!=null) event.value = util.printd("dddd", d);

}

 

Is it because the the Date1 field has a format of "m/d"?  It is formatted as a date, but the year is not displayed.

JMC08作成者
Inspiring
April 22, 2020

When I use the following script I can get the date format to change from "m/d" to "m/d/yy".

var date= util.scand("mm-dd", this.getField("DATE1").value);
date.setDate(date.getDate())
if (this.getField("DATE1").value!="")
{
event.value=util.printd("mm/dd/yy",date)
}
else
{event.value=""}

 

I cannot get the script originally sugested to work to convert this to the "ddd" format.  This is the case even if the orginal field has the year in the format.

 


I got it to work...

I used the following script:

var date= util.scand("mm-dd", this.getField("DATE1").value);
date.setDate(date.getDate()+0)
if (this.getField("DATE1").value!="")
{
event.value=util.printd("ddd",date)
}
else
{event.value=""}

And I made sure the field with the script was not formated as a date in the properties.  

Thank you for your help.