Formatting Dates in fields

If you need to format a date to a specific format (for this example, we will be using YYYY-MM-DD HH:mm), it can be done via an expression.

For example, you need to format the date in a datagrid, you can set the field mapping to something like this:

MapItem.YOUREFIELD != null ? new Date(MapItem.YOUREFIELD ).toISOString().split("T")[0] + " " + (new Date(MapItem.YOUREFIELD ).getHours() < 10 ? '0' : '') + new Date(MapItem.YOUREFIELD ).getHours() + ":" + (new Date(MapItem.YOUREFIELD ).getMinutes() < 10 ? '0' : '') + new Date(MapItem.YOUREFIELD ).getMinutes() : ''

Replace YOUREFIELD with the field name from which the date is coming.

The above expression will handle cases in which the field is null (first part of the logical expression), and it will then extract parts of the Date and time and format them into a specific format.

An example of the output can be seen below:


It is important to note that this approach is not necessarily the most maintainable one. It can become messy and difficult to maintain in the long term, especially if you have many fields to format.

A better approach will be to manipulate the data using a ForEach:

  1. Create a list of a type that looks like your DataGrid

  2. Assign the query result to the list

  3. Loop the list and amend the dates using Stadium action controls and simpler expressions

  4. Assign the list to your datagrid