Skip to main content
Liaison

Format Dates Not Stored as Date Fields

Occasionally, applications may include dates in fields that are not date fields. In cases where this happens, the built-in date formatting options are not available. Using this Java Script expression, you can convert the data in a field, formatting it as a date.

Add the JavaScript Code

You have two options when adding the JavaScript Code for this expression:

  • Create a Custom Property using this code. Once created, Custom Properties are listed among the Available Fields in the Export Builder.
  • Add the JavaScript expression directly from the Export Builder by selecting the Custom option from the Available Fields menu, and dropping it into the Columns window.

In either case, you'll have an Expression area to add your code and configure it as desired. To complete this process, in the Expression area, add the following code. (Use the view source icon at the top right to copy the code snippet.)

{
    /*Enter the field key of the target field below*/
    
    var date = new Date(TARGET_FIELD_KEY);
    var yr = date.getFullYear();
    var mon = date.getMonth()+1;
    mon = (mon.toString().length==1) ? '0' + mon : mon;
    var day = date.getDate();
    day = (day.toString().length==1) ? '0' + day : day;
    
    /*Enter the field key of the target field below*/
    dateFormatted = (TARGET_FIELD_KEY) ? mon + '/' + day + '/' + yr: ""; 
    /*will produce "MM/DD/YYYY"*/    
}

Modifying the Code

To make this code work with your desired field, you'll need to identify the Field Key that you want to use, and then modify the code to call that field.

First, identify which field you need to format. Then, use the Field Dictionary to find the Field Key for that field.

Next, put this Field Key in the code by replacing the two instances of (TARGET_FIELD_KEY) with your actual Field Key. For example, if your Field Key is forms.experiences.add_experiences.experience_start_date, the final version of your code should appear this way:

{  
    var date = new Date(forms.experiences.add_experiences.experience_start_date);
    var yr = date.getFullYear();
    var mon = date.getMonth()+1;
    mon = (mon.toString().length==1) ? '0' + mon : mon;
    var day = date.getDate();
    day = (day.toString().length==1) ? '0' + day : day;
    
    /*Enter the field key of the target field below*/
    dateFormatted = (forms.experiences.add_experiences.experience_start_date) ? mon + '/' + day + '/' + yr: ""; 
    /*will produce "MM/DD/YYYY"*/    
}

Working with the New Custom Property

If you've added this JavaScript expression as a Custom Property you can use it in other areas. For example:

  • Was this article helpful?