These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

getUTCday returning wrong data

janie_b
Registered: Feb 1 2011
Posts: 4
Answered

I have 'inherited' a PDF form from 2004 that uses getUTCday. The current desktop environment for users has Acrobat Reader 6 and over the past 6 years there have been no problems with this.
The form was updated to Adobe Acrobat 9 (no changes made - just saved as new version) and when used with Reader 9 /10 it now returns spurious results - eg it thinks that 10/10/2011 is a 0 (Sunday)despite the fact that the data value entered clearly states it is a Monday.
 
I can get round the problem by using the alternative getday but would like to know what is likely to have caused this. Any ideas?

..

My Product Information:
Acrobat Pro 9.0, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Could you post the entire code?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

try67
Expert
Registered: Oct 30 2008
Posts: 2398
[oops, double post]

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

janie_b
Registered: Feb 1 2011
Posts: 4
relevant code is
* Create a date object containing the input date which must be a Monday
and calculate forwards to deduce the dates for days within the period
*/
if (event.target.value != "")
{
function gettheDay(num)
{
var day;
switch(num)
{
case 0:
day="Sunday";
break;
case 1:
day="Monday";
break;
case 2:
day="Tuesday";
break;
case 3:
day="Wednesday";
break;
case 4:
day="Thursday";
break;
case 5:
day="Friday";
break;
case 6:
day="Saturday"
break;
default:
day="Invalid day"
}
return day;
}
var enddatefield = this.getField("PeriodEndDate")
var finputdate = this.getField("PeriodStartDate")
var datestr = finputdate.value
var d0 = util.scand("dd/mm/yyyy", datestr);
var dayofdate = gettheDay(d0.getUTCDay())
if (gettheDay(d0.getUTCDay()) != "Monday")
{
app.alert("The date you entered is for a " + dayofdate +", "+ d0 +", "+ d0.getUTCDay() + ". The period must start on a Monday")
finputdate.value = ""
finputdate.setFocus()
}
else
{

..

try67
Expert
Registered: Oct 30 2008
Posts: 2398
Accepted Answer
This was a tricky one...

On March 27 2011 the UTC switches to daylight savings time, as a result an extra hour is added to that day. This seems to cause some inconsistencies within the Date object.
The solution would be to add two hours to your Date variable. That way you will always be on the right day.
You can do it with the following code:

d.setTime(d.getTime()+7200000);

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

janie_b
Registered: Feb 1 2011
Posts: 4
thanks

..

janie_b
Registered: Feb 1 2011
Posts: 4
But why would the same code give a different answer for the same date in a different version of acrobat?

..

try67
Expert
Registered: Oct 30 2008
Posts: 2398
Possibly a different (newer) implementation of the JavaScript core.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
Just be aware that UTC time as measured and transmitted by the Royal Observatory at Greenwich, England does not recognize Daylight Savings Time, DST,. Only the local location may observe DST as determined by local law. The date time object also include the necessary Timezone Offset if your computer is properly configured and system clock synchronized to one of the national time standard sources.

Please be careful about which methods you are using to extract or set certain date and time properties and test these scripts at the various end points of the day for your local and the Greenwich Meridian.

George Kaiser