-
Notifications
You must be signed in to change notification settings - Fork 277
RDSC-3621 format epoch to date string #1674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mich-elle-luna
merged 16 commits into
redis:main
from
ilianiliev-redis:RDSC-3621-format-epoch-to-date-string
Jun 17, 2025
Merged
Changes from 2 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7d14d68
Moving time formatting examples to separate page
ilianiliev-redis 27a1286
Adding PostgreSQL examples
ilianiliev-redis 35f0968
Update content/integrate/redis-data-integration/data-pipelines/transf…
ilianiliev-redis 51ff789
Update content/integrate/redis-data-integration/data-pipelines/transf…
ilianiliev-redis f5472d0
Update content/integrate/redis-data-integration/data-pipelines/transf…
ilianiliev-redis 2adb15b
Update content/integrate/redis-data-integration/data-pipelines/transf…
ilianiliev-redis 60e7113
Update content/integrate/redis-data-integration/data-pipelines/transf…
ilianiliev-redis 0aa0f55
Update content/integrate/redis-data-integration/data-pipelines/transf…
ilianiliev-redis 2d03950
Update content/integrate/redis-data-integration/data-pipelines/transf…
ilianiliev-redis fd45394
Update content/integrate/redis-data-integration/data-pipelines/transf…
ilianiliev-redis 2f49c22
Update content/integrate/redis-data-integration/data-pipelines/transf…
ilianiliev-redis a374f8b
Update content/integrate/redis-data-integration/data-pipelines/transf…
ilianiliev-redis 5661808
Update content/integrate/redis-data-integration/data-pipelines/transf…
ilianiliev-redis 8960a3f
Update content/integrate/redis-data-integration/data-pipelines/transf…
ilianiliev-redis cd63284
Update content/integrate/redis-data-integration/data-pipelines/transf…
ilianiliev-redis df6f801
Update content/integrate/redis-data-integration/data-pipelines/transf…
ilianiliev-redis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
189 changes: 189 additions & 0 deletions
189
...ntegration/data-pipelines/transform-examples/formatting-date-and-time-values.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| --- | ||
| Title: Formatting date and time values | ||
| alwaysopen: false | ||
| categories: | ||
| - docs | ||
| - integrate | ||
| - rs | ||
| - rdi | ||
| description: null | ||
| group: di | ||
| linkTitle: Formatting date and time values | ||
| summary: Redis Data Integration keeps Redis in sync with a primary database in near | ||
| real time. | ||
| type: integration | ||
| weight: 40 | ||
| --- | ||
|
|
||
| How to format date and time values depends on the source database and the data type of the field, and how they are represented in the incoming record. Below are 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 epoch | ||
ilianiliev-redis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ```yaml | ||
| 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 string representation of the timestamp with time zone information. | ||
|
|
||
| - `TIMESTAMP WITH LOCAL TIME ZONE` - the value is represented as string representation of the timestamp with local time zone information. | ||
ilianiliev-redis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Both `TIMESTAMP WITH TIME ZONE` and `TIMESTAMP WITH LOCAL TIME ZONE` are supported by SQLite and can be formatted using the `STRFTIME` function. | ||
ilianiliev-redis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```yaml | ||
| 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 the `STRFTIME` or `DATE` functions to format it. | ||
| ```yaml | ||
| 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. You have to divide the value by 1000 to convert it to seconds since epoch and then use the `STRFTIME` function to format it. | ||
ilianiliev-redis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ```yaml | ||
| 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. and for `datetime2(7)` it is the number of nanoseconds since epoch. You can use the same approach as for `datetime` but you need to divide by 1000, 1000000 or 1000000000 depending on the precision. | ||
ilianiliev-redis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - `time` - the time of milliseconds since midnight. | ||
ilianiliev-redis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ```yaml | ||
| 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 e.g. `2025-05-27T15:21:42.864Z` and `2025-01-02T14:45:30.123+05:00`. | ||
ilianiliev-redis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ```yaml | ||
| transform: | ||
| - uses: add_field | ||
| with: | ||
| fields: | ||
| - field: formatted_datetimeoffset | ||
| language: sql | ||
| expression: STRFTIME('%Y-%m-%d %H:%M:%S', event_datetimeoffset) | ||
| ``` | ||
|
|
||
|
|
||
|
|
||
|
|
||
| <!-- TODO [ilianiliev-redis]: Test and document the dynamic expressions for the rest of the supported databases - MySQL, PostgresSQL, MongoDB --> | ||
|
|
||
|
|
||
|
|
||
| ---- | ||
|
|
||
| ## 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 the `STRFTIME` or `DATE` functions to format it. | ||
| ```yaml | ||
| 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. | ||
| ```yaml | ||
| 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, example `07:15:00Z`. | ||
ilianiliev-redis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ```yaml | ||
| 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 representing the microseconds since epoch. You can use the `STRFTIME` function to format it. | ||
ilianiliev-redis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ```yaml | ||
| 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 representation of the timestamp with time zone information, where the timezone is GMT, e.g. `2025-06-07T10:15:00.000000Z` | ||
ilianiliev-redis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ```yaml | ||
| 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) | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -167,4 +167,4 @@ like the following: | |
| 6) "3:35.0" | ||
| 7) "storagesize" | ||
| 8) "6.71MB" | ||
| ``` | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.