Copy link to clipboard
Copied
I am making a form and I want to use a military formatted date 'yyyymmdd' to calculate the user's age. I have found code to find the age based off of a date formatted as 'yyyy/mm/dd', but I'm having problems finding the age after adding the slashes with javascript after inputting the date. I'm using Adobe Acrobat Pro DC on OSX 10.11.6. Thanks in advance.
Replace these two lines:
var cDob = getField(cBirthDate).value;
var cCutoff = getField(cCutoffDate).value;
With this:
var cDob = getField(cBirthDate).valueAsString;
var cCutoff = getField(cCutoffDate).valueAsString;
Copy link to clipboard
Copied
You don't need to add slashes. Just change the code so that it uses the date format you're using.
If you don't know how to do that post the code and we'll help you out.
Copy link to clipboard
Copied
Here is some code I found on another question, and like I said, it works with the dates having the slashes, but throws errors when they don't even with the format as 'yyyymmdd'
function GetField(cName) {
var oField = this.getField(cName);
if (oField == null) {
app.alert("Field " + cName + " not found.\nPlease check spelling and capitalization of the field name.", 0, 1);
}
return oField;
}
function Scand(cFormat, cDate) {
var oDate = util.scand(cFormat, cDate);
if(oDate == null) {
app.alert("Error converting " + cDate + " with format " + cFormat + "\nConversion failed.", 0, 1)
}
return oDate;
}
var cBirthDate = "App.DOB";
var cCutoffDate = "Form.Date";
var cDateFormat = "yyyymmdd";
event.value = "";
var cDob = getField(cBirthDate).value;
var cCutoff = getField(cCutoffDate).value;
if (cDob != "" && cCutoff != "") {
var oDob = Scand(cDateFormat, cDob);
var oCutoff = Scand(cDateFormat, cCutoff);
event.value = oCutoff.getFullYear() - oDob.getFullYear();
event.value = event.value - Number(oCutoff.getMonth() < oDob.getMonth());
event.value -= Number((oCutoff.getMonth() == oDob.getMonth())) && Number(oCutoff.getDate() < oDob.getDate());
}
Copy link to clipboard
Copied
Replace these two lines:
var cDob = getField(cBirthDate).value;
var cCutoff = getField(cCutoffDate).value;
With this:
var cDob = getField(cBirthDate).valueAsString;
var cCutoff = getField(cCutoffDate).valueAsString;
Copy link to clipboard
Copied
I could have sworn I did that... I feel like a complete idiot. Thanks again.
Copy link to clipboard
Copied
No need to... It's quite a tricky thing to get. Took me a couple of moments
to figure out what was going wrong.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now