Formatting date and time values
The way you format date and time values depends on the source database, the data type of the field, and how it is represented in the incoming record. Below are some examples for different databases and data types.
Oracle
Oracle supports the following date and time data types:
-
DATE
- represented by Debezium as a 64-bit integer representing the milliseconds since epochtransform: - uses: add_field with: fields: - field: formatted_date language: sql # Date is stored as a Unix timestamp in milliseconds so you need to # divide it by 1000 to convert it to seconds. expression: STRFTIME('%Y-%m-%d %H:%M:%S', DATE / 1000, 'unixepoch') # Example: 1749047572000 is transformed to 2025-06-04 14:32:52
-
TIMESTAMP
- the value is represented by Debezium as a 64-bit integer and depends on the number of decimal places of precision of the column, representing fractions of a second. For example, if the column is defined asTIMESTAMP(6)
, there are six decimal places and so the value is represented as microseconds since epoch (since there are 10^6 microseconds in each second). You can format it similarly toDATE
, but you need to divide the value by the appropriate factor based on the precision. -
TIMESTAMP WITH TIME ZONE
- the value is represented as a string containing the timestamp and time zone. -
TIMESTAMP WITH LOCAL TIME ZONE
- the value is represented as a string containing the timestamp and local time zone.SQLite supports both
TIMESTAMP WITH TIME ZONE
andTIMESTAMP WITH LOCAL TIME ZONE
. You can format them using theSTRFTIME
function.transform: - uses: add_field with: fields: - field: seconds_since_epoch language: sql # Convert the timestamp with local time zone to seconds since epoch. expression: STRFTIME('%s', TIMESTAMP_FIELD) - field: date_from_timestamp language: sql # Convert the timestamp with local time zone to date and time. expression: STRFTIME('%Y-%m-%d %H:%M:%S', TIMESTAMP_FIELD)
SQL Server
SQL Server supports the following date and time data types:
-
date
- represented by Debezium as number of days since epoch (1970-01-01). You can multiply the value by 86400 (the number of seconds in a day) to convert it to seconds since epoch and then use theSTRFTIME
orDATE
functions to format it.transform: - uses: add_field with: fields: - field: with_default_date_format language: sql # Uses the default DATE format expression: DATE(event_date * 86400, 'unixepoch') - field: with_custom_date_format language: sql # Uses the default DATE format expression: STRFTIME('%Y/%m/%d', event_date * 86400, 'unixepoch')
-
datetime
,smalldatetime
- represented by Debezium as number of milliseconds since epoch. Divide the value by 1000 to convert it to seconds since epoch and then use theSTRFTIME
function to format it.transform: - uses: add_field with: fields: - field: formatted_datetime language: sql expression: STRFTIME('%Y-%m-%d %H:%M:%S', event_datetime / 1000, 'unixepoch')
-
datetime2
- similar todatetime
but with higher precision. Fordatetime2(0-3)
, the representation is the same as fordatetime
. Fordatetime2(4-6)
, it is the number of microseconds since epoch. Fordatetime2(7)
, it is the number of nanoseconds since epoch. To convert to another time unit, you can use the same approach as fordatetime
but you need to divide by 1000, 1000000 or 1000000000 depending on the precision. -
time
- the number of milliseconds since midnight.transform: - uses: add_field with: fields: - field: formatted_time language: sql expression: TIME(event_time, 'unixepoch', 'utc')
-
datetimeoffset
- represented as a timestamp with timezone information (for example,2025-05-27T15:21:42.864Z
or2025-01-02T14:45:30.123+05:00
).transform: - uses: add_field with: fields: - field: formatted_datetimeoffset language: sql expression: STRFTIME('%Y-%m-%d %H:%M:%S', event_datetimeoffset)
PostgreSQL
PostgreSQL supports the following date and time data types:
-
date
- represented by Debezium as number of days since epoch (1970-01-01). You can multiply the value by 86400 (the number of seconds in a day) to convert it to seconds since epoch and then use theSTRFTIME
orDATE
functions to format it.transform: - uses: add_field with: fields: - field: with_default_date_format language: sql # Uses the default DATE format expression: DATE(event_date * 86400, 'unixepoch')
-
time
- the time of microseconds since midnight.transform: - uses: add_field with: fields: - field: formatted_time language: sql # Divide by 1000000 to convert microseconds to seconds expression: TIME(event_time / 1000000, 'unixepoch', 'utc')
-
time with time zone
- a string representation of the time with timezone information, where the timezone is GMT (for example,07:15:00Z
).transform: - uses: add_field with: fields: - field: formatted_time_with_tz language: sql expression: STRFTIME('%H:%M:%S', event_time_with_time_zone)
-
timestamp
- represented by Debezium as a 64-bit integer containing the microseconds since epoch. You can use theSTRFTIME
function to format it.transform: - uses: add_field with: fields: - field: formatted_timestamp language: sql # Divide by 1000000 to convert microseconds to seconds expression: STRFTIME('%Y-%m-%d %H:%M:%S', event_timestamp / 1000000, 'unixepoch')
-
timestamp with time zone
- represented by Debezium as a string containing the timestamp with time zone information, where the timezone is GMT (for example,2025-06-07T10:15:00.000000Z
).transform: - uses: add_field with: fields: - field: formatted_timestamp_with_tz language: sql # Divide by 1000000 to convert microseconds to seconds expression: STRFTIME('%Y-%m-%d %H:%M:%S', event_timestamp_with_time_zone)