getTime() etc. not working in Acrobat XI - help?

Salster123

08-06-2016

Hello,

I have been using getTime() to work out the number of days between 2 dates.

//set the variables

var oneDay = 24*60*60*1000;

var firstDate = new Date(from_date.rawValue);

var secondDate = new Date(to_date.rawValue);

//only if the 2 date fields aren't null

if ((from_date.rawValue!=null)&&(to_date.rawValue!=null)){

num_days.rawValue = Math.abs((firstDate.getTime() - secondDate.getTime())/(oneDay));

}

It has been working well in lots of versions of Adobe Reader (& other PDF readers) but not in Acrobat Reader XI.

I have tested getYear() and getMonth() and they don't work either!.

I'm very confused and wonder whether anyone else has this problem? (Just in Acrobat Reader XI).

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

_Bruce_Robertson

MVP

13-06-2016

Hi,

Are the fields from_date and to_date Date Fields?  If they are then the rawValue will be in the yyyy-mm-dd.  Using the Date constructor to parse a date has always been inconsistent across environments.  I think that Reader DC (which has JavaScript 2.8) handles the yyyy-mm-dd but the earlier versions don't (which expect the dd mmm yyyy format).  This might depend on the locale used as well.  You might be better using the util.scand() method which is more reliable, so;

//set the variables

var oneDay = 24*60*60*1000;

var firstDate = new Date(util.scand("yyyy-mm-dd", from_date.rawValue).setHours(0,0,0,0));

var secondDate = new Date(util.scand("yyyy-mm-dd", to_date.rawValue).setHours(0,0,0,0));

//only if the 2 date fields aren't null

if ((from_date.rawValue!=null)&&(to_date.rawValue!=null)){

    num_days.rawValue
= Math.abs((firstDate.getTime() - secondDate.getTime())/(oneDay));

}

Regards

Bruce

Answers (1)

Answers (1)

Salster123

13-06-2016

Wonderful! That makes me so happy - my work around was using FormCalc, then sending the time to hidden fields to use in JavaScript - not ideal as I prefer to use JavaScript. The only issue I have is that this gives me the positive difference, not a negative one. Thinking that might be the Maths.abs though! Thanks again - Sally.