Custom Date format not working

New to Connect after 15+ years of PPTalk, and having lots of trouble. I don’t know much HTML or Javascript, and translating it from web design to Connect is confusing.

Capturing a date from PDF data source, example “March 17, 2025.” When field type is set as date and format is “Automatic”, value is converted to “03/17/2025 12:00 AM” in data model, which is ideal except for time.

When format is set to “Custom” to remove the time, value becomes blank.

Is this because it is PDF data source? Should I capture as string then convert to date format using Javascript? As if I know how to do that.

Fields are to be extracted and written to .CSV file in Workflow for PDF index, so not even imaging on page. But this is the first thing I have tried to do and I hit a roadblock.

Any insight would be appreciated.

THX

No, this is not because the data source is PDF. This will also happen when the data source is XML or CSV, for example.

As for using JavaScript: In case you are not going to do anything with the extracted date value other than writing it to CSV output, then this can be achieved by executing the following steps:

  1. View the Step Properties of the Extract step
  2. Change the Type option from Date to String
  3. Change the Based on option from Location to JavaScript
  4. Apply something similar to the below JavaScript code in the Expression field:
let result = "";
let val = data.extract(6, 43, 8, 8);
let date = new Date(val);

if (!isNaN(date)) {
	result += ("0" + date.getDate()).slice(-2) + "/";
	result += ("0" + (date.getMonth() + 1)).slice(-2) + "/";
	result += date.getFullYear();
}

result;

Note: The condition !isNaN(date) is applied to check whether the value is a valid date. ("0" + date.getDate()).slice(-2) and ("0" + (date.getMonth() + 1)).slice(-2) are applied to add a leading zero to these values when they are below 10 (example: 808). (date.getMonth() + 1) is applied because the method getMonth() returns a zero-based value.

Tip: Replace data.extract(6, 43, 8, 8) with what is shown when you switch the Based on option from Location to JavaScript for the first time.

If you simply want to emit what you capture, then setting the “Type” to “String” is all you really need to do. Setting it to “Date”, regardless of what “Pattern” you use, will always produce a Date Object, which will have the time component. The pattern is your “input mask”; the “Pattern” doesn’t affect the output. The output of a Date type is a Date Object, which has a time component. In the Template, there are Formatter functions that control how that Date obect is rendered (with or without the time, the Month as a number vs. a text etc.).

Since you’re not trying to express the date on the template, then you can avoid all of this by using the “String” type in the Step Properties.

Thank you for this lesson. It did exactly what I needed (once I swapped the get.Month and getDate for US date format).

I expect I will be spending a lot of time on these forums in the coming months, especially if I get quick and helpful responses like this.

This forum has been key to helping me through several thorny problems. There is a good deal of participation from veteran PlanetPress users, and OL support staff, current and retired! One of the most responsive vendor forums I’ve experienced.

1 Like