Skip to main content
Known Participant
October 25, 2023
Question

Changing Duplicate Date Box Format

  • October 25, 2023
  • 1 reply
  • 2560 views

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. 

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
October 26, 2023

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. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Known Participant
October 27, 2023

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

Known Participant
November 18, 2023

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/

 


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.