Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session

Date Format

Avatar

Former Community Member
Hi,



I need to compare an entered date with the current date.

Also this topic came up several times in the forum, I could not find a proper solution. My current coding looks like this:



x = new Date();

currDate = parseFloat((x.getYear()+1900).toString() + (x.getMonth()+1).toString()+(x.getDate()).toString());



enteredDate = parseFloat((this.rawValue).replace(/-/g,""));



if (currDate < enteredDate)

{

xfa.host.messageBox ("Invalid date! Please enter a date before the current date");

this.rawValue = "";

}



But in order to compare the dates, I still need to format the month in MM, if the entered month is below 10 (Same for day). How can I change the formatting from e.g. "5" to "05"?
4 Replies

Avatar

Level 7
Why not just compare the number of days from epoch date for the comparison?

Avatar

Former Community Member
Hi Geo,



can you please provide me some coding?



Thx, Claudi

Avatar

Former Community Member
Why not use Acrobat's built-in date functions in order to parse a date:




var objToday = new Date();

var objDate = util.scand("dd-mmm-yyyy", this.rawValue); // uses the current local time!



console.println(objToday - objDate); // true (as of may-31)



You may have to adjust the date pattern. Have a look at:


Acrobat JavaScript Scripting Reference (PDF, 7.1M)

On page 641+, you find the available date patterns.

Avatar

Level 7
With FormCalc one can use the "Date2Num()" function to obtain the number of days from the epoch date.



Date2Num(d1[, f1[, k1]]) Returns the number of days since the epoch, given a date string.



One needs to specify the date string and format and the local (language) identifier is optional.