ReformatDate Operator - Haufe-Lexware/haufe.no-frills-transformation GitHub Wiki
The ReformatDate operator may be used to transform date strings from one format to another.
| What | Type |
|---|---|
| Syntax | ReformatDate(dateString, inputFormat, outputFormat) |
dateString |
string |
inputFormat |
string |
outputFormat |
string |
| Return type | string |
The operator will parse the given dateString in the inputFormat and transform it to the outputFormat. If the dateString string cannot be parsed correctly, the transformation process will be cancelled with an appropriate error message.
The documentation on which kinds of date format strings (for inputFormat and outputFormat) are allowed, please see here:
- https://msdn.microsoft.com/en-us/library/vstudio/8kb3ddd4(v=vs.100).aspx (Custom Date and Time Format Strings)
Example:
<Field name="Date">ReformatDate($date, "dd.MM.yyyy", "yyyy-MM-dd")</Field>This example reformats the content of the field $date from the German date format to a standard date format, e.g. 05.11.2014 is reformatted to 2014-11-05. Obviously, this is a lot more convenient than reformatting using e.g. Substring and Concat.
Caution: Passing empty strings into the ReformatDate operator is seldom a good idea. Use the If Operator, or [[a custom operator with a Switch tag|Using Custom Operators]] to rule this out:
<Field name="Date">If(Not(IsEmpty($date)), ReformatDate($date, "dd.MM.yyyy", "yyyy-MM-dd"), "")</Field>