Working with data from multiple sources often presents challenges, especially when dealing with date formats. This article addresses a common problem encountered when using FME (Feature Manipulation Engine) to process data from Excel files with inconsistent date formats and provides tested solutions for converting them into a uniform format.
A common issue arises when importing data from multiple Excel files. One attribute intended to represent a date might appear in different formats, such as "01.02.2010" (DD.MM.YYYY) in one file and "20100304" (YYYYMMDD) in another. This inconsistency can disrupt data processing, especially when subsequent transformations rely on a specific date format.
Excel's flexibility can be a double-edged sword. While it allows users to format cells in various ways, this freedom can lead to inconsistencies when data is compiled from multiple sources. It's crucial to recognize that what Excel displays might not be the actual underlying data format. Therefore, it's essential to verify the actual data within FME using the FME Data Inspector.
One approach is to use the DateTimeConverter transformer in conjunction with a Tester transformer. This method involves:
%d.%m.%Y
and the output format to %Y%m%d
.%Y%m%d
and the output format to %Y%m%d
(no conversion needed).Pros:
Cons:
A more robust solution involves using the AttributeCreator transformer with the @DateTimeParse
function. This method allows FME to attempt to automatically detect and parse various date formats.
@DateTimeParse(@Value(DateAttributeName), FME|ISO, repair)
. This attempts to parse the date using recognized FME and ISO date/time formats. The repair
option attempts to correct minor formatting issues.@DateTimeParse
function, explicitly specifying the format. For example: @DateTimeParse(@Value(DateAttributeName), %d.%m.%Y, repair)
.Pros:
Cons:
AttributeCreator:
New Attribute: ParsedDate
Attribute Value: @DateTimeParse(@Value(OriginalDate), FME|ISO, repair)
Conditional Value:
Condition: @IsNull(@Value(ParsedDate))
Attribute Value: @DateTimeParse(@Value(OriginalDate), %d.%m.%Y, repair)
Conditional Value:
Condition: @IsNull(@Value(ParsedDate))
Attribute Value: @DateTimeParse(@Value(OriginalDate), %Y%m%d, repair)
Handling variable date formats in FME requires a combination of understanding the data, leveraging FME's transformation capabilities, and implementing robust error handling. By using the techniques described in this article, you can effectively convert inconsistent date formats into a uniform standard, ensuring accurate and reliable data processing. Remember to prioritize data standardization at the source to minimize future challenges.
This article focuses on using the DateTimeConverter and AttributeCreator transformers. For additional information on data transformation, see our article on [Data Transformation Techniques in FME](Internal Link to related article on data transformation).