DateFormatter
Reformats and replaces date or time strings into a new date format.
The source string must be in a date and/or time format supported by the transformer. For additional information, see the Source Date Format parameter.
Limitations:
- Dates earlier than 1902 are not supported.
- If your date string contains ".", then the Source Date Format parameter must be specified. E.g., to process dates like 23.03.2015, the source format %d.%m.%Y is required.
- Fractional seconds are not supported. E.g., for the date string 2015-03-23 10:23:45.213, the .213 will be ignored when using Unknown - Automatic Detection.
Parameters
Choose the attributes to reformat and replace.
Specified the expected format of the source date. See the ‘Date Format Symbols’ section for details on how to specify the date.
If you do not know the format, select Unknown – Automatic Detection and the system will try to interpret values as a date. It is recommended whenever possible to provide the Source Date Format to avoid unexpected results. In particular, when using ISO8601 point-in-time specifications, the output could vary depending on the local timezone, if the timezone information is not part of the data/time string.
The destination format that valid dates are converted to. See the ‘Date Format Symbols’ section for details on how to specify the date.
If the value of the attribute does not match the specified Source Date Format, it will be considered invalid and set to the specified value. For more information about options for setting this parameter, see Transformer Parameter Menu Options.
Since the DateFormatter supports relative dates, dates that match the format but can overflow are considered to be valid. For example, if the Source Date Format is set to %Y%m%d, an attribute with value ‘20090133’ will be set to ‘20090202’. However, if the Source Date Format is %Y%m%d%H%M%S, an attribute with value ‘20090133’ will be considered an invalid date.
Date Format Symbols
The format specifiers determine the format for the destination and source date format parameters.
"-" |
Quoted strings (%Y"-"%m"-"%d) |
%% |
Insert a percent symbol (%) |
%a |
Abbreviated weekday name (Mon, Tue, etc.). |
%A |
Full weekday name (Monday, Tuesday, etc.). |
%b |
Abbreviated month name (Jan, Feb, etc.) (same as %h). |
%B |
Full month name. |
%c |
Locale specific date and time. The format for date and time in the default "C" locale on UNIX/Mac is "%a %b %d %H:%M:%S %Y". On Windows, this value is the locale specific long date and time, as specified in the Regional Options control panel settings. |
%C |
First two digits of the four-digit year (19 or 20). |
%d |
Day of month (01 - 31). |
%D |
Date as %m/%d/%y. |
%e |
Day of month (1 - 31), no leading zeros. |
%h |
Abbreviated month name (Jan, Feb, etc.) (same as %b). |
%H |
Hour in 24-hour format (00 - 23). |
%I |
Hour in 12-hour format (01 - 12). |
%j |
Day of year (001 - 366). |
%k |
Hour in 24-hour format, without leading zeros (0 - 23). |
%l |
Hour in 12-hour format, without leading zeros (1 - 12). |
%m |
Month number (01 - 12). |
%M |
Minute (00 - 59). |
%n |
Insert a newline. |
%p |
AM/PM indicator. |
%r |
Time in a locale-specific "meridian" format. The "meridian" format in the default "C" locale is "%I:%M:%S %p". |
%R |
Time as %H:%M. |
%s |
Count of seconds since the epoch, expressed as a decimal integer. |
%S |
Seconds (00 - 59). |
%t |
Insert a tab. |
%T |
Time as %H:%M:%S. |
%u |
Weekday number (Monday = 1, Sunday = 7). |
%U |
Week of year (00 - 52), Sunday is the first day of the week. |
%V |
Week of year according to ISO-8601 rules. Week 1 of a given year is the week containing 4 January. |
%w |
Weekday number (Sunday = 0, Saturday = 6). |
%W |
Week of year (00 - 52), Monday is the first day of the week. |
%x |
Locale-specific date format. The format for a date in the default "C" locale for UNIX/Mac is "%m/%d/%y". On Windows, this value is the locale-specific short date format, as specified in the Regional Options control panel settings. |
%X |
Locale-specific 24-hour time format. The format for a 24-hour time in the default "C" locale for UNIX/Mac is "%H:%M:%S". On Windows, this value is the locale-specific time format, as specified in the Regional Options control panel settings. |
%y |
Year without century (00 - 99). |
%Y |
Year with century (e.g. 1990) |
%Z |
Time zone name. |
Automatic Detection
When using automatic detection:
- The source date is assumed to be in a standard date and/or time string, which can include standard time zone mnemonics. If only a time is specified, the current date is assumed. If the string does not contain a time zone mnemonic, the local time zone is assumed.
- In a numerical date such as 10/11/99, the first number is always interpreted as the month. (So the given date is October 11, not November 10.) A date such as 13/1/05 will therefore produce an error, because 13 is an invalid month. If the date is known to be of the form DD/MM/YY, the Source Date Format parameter should be used to specify the format as %d/%m/%y.
- Each date is treated on a feature-by-feature basis; no attempt is made to determine a common format amongst all input.
- Relative Dates: The DateFormatter can accept relative dates as an input string. For example, if today is Monday, 25-Oct-2010, it can convert next thursday to "28-Oct-2010" or three years ago to "25-Oct-2007". See the FME Knowledge Center link below for workspace examples.
- If the source attribute is a 14-digit number and Source Date Format is set to Unknown – Automatic Detection, its format will be interpreted as YYYYMMDDHHMMSS, as formatted by the Oracle reader.
- The source date can consist of zero or more specifications of the following types:
Type | Description |
---|---|
Time |
Time of the day. Acceptable formats are: hh[:mm[:ss]] [meridian] [zone] hhmm [meridian] [zone] If no meridian is specified, hh is interpreted on a 24-hour clock. Warning: An integer less than 24 will be interpreted as an hour, with the date assumed to be today's date. Therefore, an input of "0" is taken to mean "today at midnight." If zero values are to be considered invalid, they must be filtered using a Tester before reaching the DateFormatter. |
Date |
A specific month and day with optional year. The acceptable formats are: mm/dd[/yy] monthname dd [, yy] dd monthname [yy] day (e.g., Monday) The default year is the current year. If the year is less than 100, we treat the years 00-68 as 2000-2068 and the years 69-99 as 1969-1999. Note: Some older UNIX and Windows platforms cannot represent the years 38-70, so an error may result if these years are used. |
ISO 8601 point-in-time |
An ISO 8601 point-in-time specification, such as YYYYMMDDThhmmss, where T is the literal T, YYYYMMDD hhmmss, or YYYYMMDDThh:mm:ss. Note: Output may vary depending on your local timezone if timezone information is not part of the date/time specification. |
Relative time |
A specification relative to the current time. The format is number unit. Acceptable units are year; fortnight; month; week; day; hour; minute (or min); second (or sec). The unit can be specified as a singular or plural, as in 3 weeks. These modifiers may also be specified: tomorrow; yesterday; today; now; last; next; ago. The actual date is calculated according to the following steps. First, any absolute date and/or time is processed and converted. Using that time as the base, day-of-week specifications are added. Next, relative specifications are used. If a date or day is specified, and no absolute or relative time is given, midnight is used. Finally, a correction is applied so that the correct hour of the day is produced after allowing for daylight savings time differences and the correct date is given when going from the end of a long month to a short month. Daylight savings time correction is applied only when the relative time is specified in units of days or more, i.e., days, weeks, fortnights, months or years. |
Editing Transformer Parameters
Using a set of menu options, transformer parameters can be assigned by referencing other elements in the workspace. More advanced functions, such as an advanced editor and an arithmetic editor, are also available in some transformers. To access a menu of these options, click beside the applicable parameter. For more information, see Transformer Parameter Menu Options.
Transformer Categories
Search FME Knowledge Center
Search for samples and information about this transformer on the FME Knowledge Center.