content/integrate/redis-data-integration/data-pipelines/transform-examples/formatting-date-and-time-values.md
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 supports the following date and time data types:
DATE - represented by Debezium as a 64-bit integer representing the milliseconds since epoch
name: Format Oracle DATE field
transform:
- 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 as TIMESTAMP(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 to DATE, 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 and TIMESTAMP WITH LOCAL TIME ZONE. You can format them using the STRFTIME function.
name: Format Oracle TIMESTAMP WITH TIME ZONE
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 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 the STRFTIME or DATE functions to format it.
name: Format SQL Server date field
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 the STRFTIME function to format it.
name: Format SQL Server datetime field
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 to datetime but with higher precision. For datetime2(0-3), the representation is the same as for datetime. For datetime2(4-6), it is the number of microseconds since epoch. For datetime2(7), it is the number of nanoseconds since epoch. To convert to another time unit, you can use the same approach as for datetime but you need to divide by 1000, 1000000 or 1000000000 depending on the precision.
time - the number of milliseconds since midnight.
name: Format SQL Server time field
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 or 2025-01-02T14:45:30.123+05:00).
name: Format SQL Server datetimeoffset field
transform:
- uses: add_field
with:
fields:
- field: formatted_datetimeoffset
language: sql
expression: STRFTIME('%Y-%m-%d %H:%M:%S', event_datetimeoffset)
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 the STRFTIME or DATE functions to format it.
name: Format PostgreSQL date field
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.
name: Format PostgreSQL time field
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).
name: Format PostgreSQL time with time zone
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 the STRFTIME function to format it.
name: Format PostgreSQL timestamp field
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).
name: Format PostgreSQL timestamp with time zone
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)