{
  "id": "formatting-date-and-time-values",
  "title": "Formatting date and time values",
  "url": "https://redis.io/docs/latest/integrate/redis-data-integration/data-pipelines/transform-examples/formatting-date-and-time-values/",
  "summary": "",
  "tags": [
    "docs",
    "integrate",
    "rs",
    "rdi"
  ],
  "last_updated": "2026-04-01T08:10:08-05:00",
  "page_type": "content",
  "content_hash": "7055e02cbf797d33d5fbd57f077a763f973e8d403365a1cc04476043e81eac7f",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "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."
    },
    {
      "id": "oracle",
      "title": "Oracle",
      "role": "content",
      "text": "Oracle supports the following date and time data types:\n\n- `DATE` - represented by Debezium as a 64-bit integer representing the milliseconds since epoch\n  [code example]\n- `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).\nYou can format it similarly to `DATE`, but you need to divide the value by the appropriate factor based on the precision.\n\n- `TIMESTAMP WITH TIME ZONE` - the value is represented as a string containing the timestamp and time zone.\n\n- `TIMESTAMP WITH LOCAL TIME ZONE` - the value is represented as a string containing the timestamp and local time zone.\n\n  SQLite supports both `TIMESTAMP WITH TIME ZONE` and `TIMESTAMP WITH LOCAL TIME ZONE`. You can format them using the `STRFTIME` function.\n\n  [code example]\n\n----"
    },
    {
      "id": "sql-server",
      "title": "SQL Server",
      "role": "content",
      "text": "SQL Server supports the following date and time data types:\n\n- `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.\n  [code example]\n\n- `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.\n  [code example]\n\n- `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.\n\n- `time` - the number of milliseconds since midnight.\n  [code example]\n\n- `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`). \n  [code example]\n\n\n\n\n<!-- TODO [ilianiliev-redis]: Test and document the dynamic expressions for the rest of the supported databases - MySQL, PostgresSQL, MongoDB -->\n\n\n\n----"
    },
    {
      "id": "postgresql",
      "title": "PostgreSQL",
      "role": "content",
      "text": "PostgreSQL supports the following date and time data types:\n\n- `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.\n  [code example]\n\n- `time` - the time of microseconds since midnight.\n  [code example]\n\n- `time with time zone` - a string representation of the time with timezone information, where the timezone is GMT (for example, `07:15:00Z`).\n  [code example]\n\n- `timestamp` - represented by Debezium as a 64-bit integer containing the microseconds since epoch. You can use the `STRFTIME` function to format it.\n  [code example]\n\n- `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`).\n  [code example]"
    }
  ],
  "examples": [
    {
      "id": "oracle-ex0",
      "language": "yaml",
      "code": "name: Format Oracle DATE field\n  transform:\n  - uses: add_field\n    with:\n      fields:\n        - field: formatted_date\n          language: sql\n          # Date is stored as a Unix timestamp in milliseconds so you need to\n          # divide it by 1000 to convert it to seconds.\n          expression: STRFTIME('%Y-%m-%d %H:%M:%S', DATE / 1000, 'unixepoch')\n          # Example: 1749047572000 is transformed to 2025-06-04 14:32:52",
      "section_id": "oracle"
    },
    {
      "id": "oracle-ex1",
      "language": "yaml",
      "code": "name: Format Oracle TIMESTAMP WITH TIME ZONE\n  transform:\n    - uses: add_field\n      with:\n        fields:\n          - field: seconds_since_epoch\n            language: sql\n            # Convert the timestamp with local time zone to seconds since epoch.\n            expression: STRFTIME('%s', TIMESTAMP_FIELD)\n\n          - field: date_from_timestamp\n            language: sql\n            # Convert the timestamp with local time zone to date and time.\n            expression: STRFTIME('%Y-%m-%d %H:%M:%S', TIMESTAMP_FIELD)",
      "section_id": "oracle"
    },
    {
      "id": "sql-server-ex0",
      "language": "yaml",
      "code": "name: Format SQL Server date field\n  transform:\n    - uses: add_field\n      with:\n        fields:\n          - field: with_default_date_format\n            language: sql\n            # Uses the default DATE format\n            expression: DATE(event_date * 86400, 'unixepoch')\n\n          - field: with_custom_date_format\n            language: sql\n            # Uses the default DATE format\n            expression: STRFTIME('%Y/%m/%d', event_date * 86400, 'unixepoch')",
      "section_id": "sql-server"
    },
    {
      "id": "sql-server-ex1",
      "language": "yaml",
      "code": "name: Format SQL Server datetime field\n  transform:\n    - uses: add_field\n      with:\n        fields:\n          - field: formatted_datetime\n            language: sql\n            expression: STRFTIME('%Y-%m-%d %H:%M:%S', event_datetime / 1000, 'unixepoch')",
      "section_id": "sql-server"
    },
    {
      "id": "sql-server-ex2",
      "language": "yaml",
      "code": "name: Format SQL Server time field\n  transform:\n    - uses: add_field\n      with:\n        fields:\n          - field: formatted_time\n            language: sql\n            expression: TIME(event_time, 'unixepoch', 'utc')",
      "section_id": "sql-server"
    },
    {
      "id": "sql-server-ex3",
      "language": "yaml",
      "code": "name: Format SQL Server datetimeoffset field\n  transform:\n  - uses: add_field\n    with:\n      fields:\n        - field: formatted_datetimeoffset\n          language: sql\n          expression: STRFTIME('%Y-%m-%d %H:%M:%S', event_datetimeoffset)",
      "section_id": "sql-server"
    },
    {
      "id": "postgresql-ex0",
      "language": "yaml",
      "code": "name: Format PostgreSQL date field\n    transform:\n        - uses: add_field\n          with:\n            fields:\n              - field: with_default_date_format\n                language: sql\n                # Uses the default DATE format\n                expression: DATE(event_date * 86400, 'unixepoch')",
      "section_id": "postgresql"
    },
    {
      "id": "postgresql-ex1",
      "language": "yaml",
      "code": "name: Format PostgreSQL time field\n  transform:\n    - uses: add_field\n      with:\n        fields:\n          - field: formatted_time\n            language: sql\n            # Divide by 1000000 to convert microseconds to seconds\n            expression: TIME(event_time / 1000000, 'unixepoch', 'utc')",
      "section_id": "postgresql"
    },
    {
      "id": "postgresql-ex2",
      "language": "yaml",
      "code": "name: Format PostgreSQL time with time zone\n  transform:\n    - uses: add_field\n      with:\n        fields:\n          - field: formatted_time_with_tz\n            language: sql\n            expression: STRFTIME('%H:%M:%S', event_time_with_time_zone)",
      "section_id": "postgresql"
    },
    {
      "id": "postgresql-ex3",
      "language": "yaml",
      "code": "name: Format PostgreSQL timestamp field\n  transform:\n    - uses: add_field\n      with:\n        fields:\n          - field: formatted_timestamp\n            language: sql\n            # Divide by 1000000 to convert microseconds to seconds\n            expression: STRFTIME('%Y-%m-%d %H:%M:%S', event_timestamp / 1000000, 'unixepoch')",
      "section_id": "postgresql"
    },
    {
      "id": "postgresql-ex4",
      "language": "yaml",
      "code": "name: Format PostgreSQL timestamp with time zone\n  transform:\n    - uses: add_field\n      with:\n        fields:\n          - field: formatted_timestamp_with_tz\n            language: sql\n            # Divide by 1000000 to convert microseconds to seconds\n            expression: STRFTIME('%Y-%m-%d %H:%M:%S', event_timestamp_with_time_zone)",
      "section_id": "postgresql"
    }
  ]
}
