Script Examples: Change the Format of a Date

You can use a Script data source to convert a date value obtained from a database and processed by Loftware Enterprise™ SP into a human readable format suitable for printing.

For example, an Oracle database table can have a column of data type DATE. In Oracle SQLPlus or SQL Developer, the values in this table column are displayed in a format of dd-MMM-yy. However, when the table is used as a Database data source in Loftware Enterprise SP, Loftware Enterprise SP receives the date value in Epoch timeClosed The number of seconds since 00:00:00 UTC on 1 January 1970, not including leap seconds.. By default, the Database data source would return a value such as 13849236000000 at print time instead of a human readable date. For more information, see Time Values in Loftware Enterprise SP.

You can use a Script data source with MAP functions to convert the date from Epoch time to a human readable format appropriate for printing. In this example, the Database data source column /DS_0001/DATE_COL is passed as a parameter to the MAP.getDateValue() method. This method converts the Epoch time value, such as 13849236000000, obtained from the Database data source to a human readable format, such as Wed Nov 20 00:00:00 EST 2408.

// Use the MAP function to change the date value from Epoch time to a human readable date format.

var dateVal = MAP.getDateValue("/DS_0001/DATE_COL");

 

// Create an instance of the Variable Text field to which you want to assign the human readable date value.

var text1 = getField("/Body/Text0003");

 

// Assign the human readable date value to the field you want to print.

text1.setData(dateVal);