Working with date and time data can be tricky, especially when dealing with different formats. This article addresses a common challenge faced by FME (Feature Manipulation Engine) users: converting dates from various Excel formats into a consistent format for further processing.
Many FME users encounter situations where date attributes in Excel files have varying formats. One file might have dates in the dd.mm.yyyy
format (e.g., 01.02.2010), while another uses yyyymmdd
(e.g., 20100304). This inconsistency can cause problems when you need to perform operations based on a specific date format.
yyyymmdd
FormatThe primary objective is to convert all incoming date attributes, regardless of their original format, into the yyyymmdd
format within FME. This standardization ensures that subsequent transformer conditions and processes work correctly.
Using the DateTimeConverter transformer with a specified input format (e.g., %d.%m.%Y$
) and an output format (%Y%m%d
) might seem like a direct solution. However, when FME encounters dates in a different format, the conversion fails, resulting in null
values in the rejected output.
Here's a breakdown of effective strategies to handle diverse date formats in FME:
1. Data Inspection is Key
2. Conditional Conversion with the Tester Transformer
Tester
transformer to identify date formats based on specific patterns. For example, check if the attribute contains a "." (period). If it does, it likely follows the dd.mm.yyyy
format.DateTimeConverter
transformers, each configured with the appropriate input format.FeatureMerger
or similar transformer to bring the data back together.3. Dynamic Date Parsing with AttributeCreator
@DateTimeParse()
Function: Utilize the @DateTimeParse()
function within an AttributeCreator
transformer to dynamically parse dates.FME|ISO
option, which tries to automatically detect common FME and ISO date formats.NULL
values after the initial parse. If a date couldn't be parsed, it indicates that it's in a different format.AttributeCreator
with different variations of year, month, and day arrangements in the @DateTimeParse()
function to handle other potential formats.4. Utilizing FME and ISO Date/Time Formats
5. Addressing Ambiguity
6. Data Governance and Standardization
Example FME Workflow Snippet
# Example using Tester and DateTimeConverter
Tester:
- Condition: Attribute contains "." (period)
- True: DateTimeConverter_DMY
- False: DateTimeConverter_YMD
DateTimeConverter_DMY:
- Input Format: %d.%m.%Y$
- Output Format: %Y%m%d
DateTimeConverter_YMD:
- Input Format: %Y%m%d
- Output Format: %Y%m%d
Key Considerations:
By combining these strategies, you can create a robust FME workflow that effectively handles various date formats and converts them into a consistent yyyymmdd
format, ensuring the reliability of your data processing pipelines. Remember to prioritize data inspection, use conditional logic, and consider implementing data governance practices to prevent future inconsistencies.