FORMAT-DATETIME Function

Converts a date-time string value from one format to another, with the option to supply a default value if the conversion is unsuccessful.

Purpose

Used for converting date-time strings in CSV and HL7 records from one format to another. For example, an input value “1997-04-01” can be converted and output as “April 1, 1997”.

Internally, this function first parses the provided input from a string to a .NET date-time object, then it outputs the date-time value as a string again with the specified output format. Thus apart from being used for re-formatting a date, this function can also be used as a way to separate the date and time elements from a whole date-time string.

For parsing input date-time source value and defining the output format, it uses the “date and time format strings” as defined by Microsoft. Also here are some formatting strings examples.

Format

FORMAT-DATETIME(source-data-element, input-parsing-format, output-format [, on-error-default])

The function takes 3 or 4 parameters, the last parameter specifies a default value of the conversion failed e.g. either the formatting strings are invalid, or the input value is unexpected.

Example

A TabularDataTransformer handler with the following config entry converts column #3 of the CSV input from a long-date format to a short-date format. Note in this example, the output only keeps the date portion of the input data.

<Parameter>
  <!-- FORMAT-DATETIME Example -->
  <Name>transformation-rule</Name>
  <Value>$3=>FORMAT-DATETIME($$,"dddd, dd MMMM yyyy HH:mm", "MM/dd/yyyy", "01/01/1900")</Value>
</Parameter>
InputOutcome
Friday, 29 May 2015 05:5005/29/2915

Related

Nil.