Copy link to clipboard
Copied
Hello,
I need assistance in changing the format of a copied date box. This would be similar to putting the = in another Excel cell and changing that cell's format. So, the main cell format is what is, but the second is different. My date text box name is DOB and the format for the date is yyyymmdd. I have another date box that has a custom script in it that changes the date to yy mm dd but would like it to be mmm d, yyyy. May I ask for assistance in changing the custom script to fit this new format?
Added the date box with the custom script named yy mm dd but looking to change to the name of mmm d yyyy. I am not sure if that matters or not. Thank you in advance.
Copy link to clipboard
Copied
Open the properties dialog for the date field.
Select the Format tab.
On the Format Category dropdown select "Date"
Select "mmm dd, yyyy" from the list of formats.
Copy link to clipboard
Copied
I would do that but the box is copied from another one. Throughout my document the date is in different formats. This particular box has this scripted in it
var f = this.getField("DOB").valueAsString;
var str = f.replace(/.{2}/g, '$& ');
var sp = str.split(" ");
var result = sp[1]+" "+sp[2]+" "+sp[3];
if(f)event.value = result;
else
event.value = "";
This takes the date form 20231026 to 23 20 26
Copy link to clipboard
Copied
Is this a custom calculation script?
The best way to convert date formats is to use the date functions, util.scand() and util.printd()
Use util.scand() to convert the date text into a date object.
Then use util.printd() to convert the date object into a formatted date string.
You can read about them here:
https://www.pdfscripting.com/public/Date-and-Time-Handling.cfm
and here:
https://acrobatusers.com/tutorials/date_time_part1/
Copy link to clipboard
Copied
Sorry for not replying back. I was about to make another posting. Yes this is a custom calculation script.
I am looking to take a text box DOB, with the format of YYYYMMDD but have it displayed MMM D YYYY in my text box QAB DOB. Being that the date changes to different formats through out the form I am looking for it ot be enter once and a script that formats in various areas.
Copy link to clipboard
Copied
One methodology is to copy the date to all the other fields in a specfic date format. The format script in each field would then parse that value with "util.scand()" and then format it with "util.printd".
Copy link to clipboard
Copied
I have no idea what that means to be honest with you.
Copy link to clipboard
Copied
try this, Add this code to the custom validation action on the DOB field.
// Parse entered date in yyyymmdd format
var oDate = util.scand("yyyymmdd", event.value);
if(oDate)
{ // If date parses, then copy to other fields
this.getField("Other Date Field").value = oDate.getTime();
}
Put this script in the Custom Format script for the "Other Date Field"
if(event.value)
event.value = util.printd("mmm d yyyy",new Date(event.value));
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Check the Javascript console for errors (ctrl-j).
Copy link to clipboard
Copied
I see the errors, but I still don't know what I am doing. Nor understand what I am looking at. The presumption from my first post may have presented false competence in scripting. I am very new to this and if it was not for the Adobe community I would just be trying to build everything in Excel from scratch.
From what I see and think I understand. I have an issue with the date on sgli date and
TypeError: this.getField(...) is null
3:Field:Validate
Which I dont know what this is to as for help to fix it.
Copy link to clipboard
Copied
The error message means that you don't use the correct field name.
Copy link to clipboard
Copied
In this line:
this.getField("Other Date Field").value
I used the name "Other Date Field" as a placeholder. You have to fill this in with the actual field name on your form where the date value will be copied.