Convert date without leading Zero

Hi,

is there a simple way to convert a date without a leading Zero,

the format is dd-mm-yyyy / 1-1-2014

I can’t convert it with the standard functions.

Hi Koen,

The following assumes you have set the field as a date field in your DataMapper configuration. The formatter object lets you format values in a script. In the sample below it takes our date field is input data and uses a pattern to format the string.

var myDate = record.fields.date;
var formattedDate = formatter.date(myDate,"dd-MM-yyyy");
results.text(formattedDate);

More information about the formatter is found here:
http://help.objectiflune.com/EN/planetpress-connect-user-guide/1.6/#designer/API/formatter.htm

An overview of the patterns is found here:
http://help.objectiflune.com/EN/planetpress-connect-user-guide/1.6/#designer/API/Date_Time_Patterns.htm

The patterns can also be used in the Text Script wizard as shown below.

Hope this is of some help,

Erik

Hi Erik,

My date is already set as Text so i can’t change the format, even if I

Because it’s formatted without the Zero it won’t work. Don’t I need to add the zero to the days and months?

I see, things are easier when you set the Field type to Date (e.g. not as String).

  1. Select the field in your Data Mode
  2. Change the Type field to Date
  3. Enter the Date/Time Format matching your input data. This way the software will recognize the data as a date (the icon of the field in the Data Model will change to a calendar icon).

had a similar problem in the past, where a date string was input with special format (which was an invalid JS format) and had to be converted to a valid format.

Done that in an Action Step which reads the date string, converts to the format needed, and assign it to a custom record field:

var dateSplitted = record.fields.datefield.split(“-”); //split the input date string

if (dateSplitted[0].length < 2) { //add zero to day number if needed

dateSplitted[0] = ‘0’ + dateSplitted[0];

}

if (dateSplitted[1].length < 2) { //add zero to month number if needed

dateSplitted[1] = ‘0’ + dateSplitted[1];

}

//output result to custom record field:

record.fields.dateConv = dateSplitted[0] + ‘-’ + dateSplitted[1] + ‘-’ + dateSplitted[2];

maybe this helps in your case as well.

This worked for me! thank you, it’s indeed an invalid JS format.

somehow it also works now without the script,

I don’t understand why it’s still displayed in english when I say it has to be Dutch

ah, simple to solve, just go to edit -> locale in designer