-
Notifications
You must be signed in to change notification settings - Fork 784
Create documentation for DATEFORMAT #11250
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
Open
dahfjkg
wants to merge
1
commit into
mendix:development
Choose a base branch
from
dahfjkg:dat/dateformat
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+53
−0
Open
Changes from all commits
Commits
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
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
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 |
|---|---|---|
|
|
@@ -1022,6 +1022,57 @@ SELECT Revenue : DATEDIFF(MONTH, End, Start ) as avg_revenue FROM Sales.Period | |
| The way the difference is calculated depends on the database. The `YEAR` difference between "2002-01-01" and "2001-12-31" will be `1` with some databases and `0` with others. | ||
| {{% /alert %}} | ||
|
|
||
| ### DATEFORMAT {#dateformat-function} | ||
|
|
||
| The `DATEFORMAT` function formats values of type Date and time as strings using a specified pattern. | ||
|
|
||
| This function was introduced in Mendix version 11.12.0. | ||
|
|
||
| #### Syntax | ||
|
|
||
| The syntax is as follows: | ||
|
|
||
| ```sql | ||
| DATEFORMAT ( expression , pattern ) | ||
| ``` | ||
|
|
||
| `expression` is a value of type Date and time. | ||
|
|
||
| `pattern` is a pattern used to convert `expression` to a string value. Only string literals are allowed. | ||
|
|
||
| #### Pattern Syntax | ||
|
|
||
| The `DATEFORMAT` OQL function uses the same pattern syntax as date parsing functions in Studio Pro, see [Parse and Format Date Function Calls](/refguide/parse-and-format-date-function-calls/). | ||
|
|
||
| #### Limitations and Database-Specific Differences | ||
|
|
||
| When an OQL query is executed, `DATEFORMAT` is converted to the corresponding database function. Due to implementation specifics of database engines, different limitations apply: | ||
|
|
||
| 1. Format letters `u`, `F`, `G`, `k`, `K` are not supported. | ||
| 2. SQL Server does not support format letters `D`, `Y`, `w`, `W`. | ||
| 3. MySQL and MariaDB do not support format letters `S` and `W`. | ||
| 4. SAP HANA does not support format letters `Y` and `w`. | ||
| 5. Format letter `h` results in different values per database: | ||
|
|
||
| 1. HSQLDB uses zero-based indexing and returns values `0` to `11` | ||
| 2. Other databases use one-based indexing and return values `1` to `12` | ||
|
|
||
| 6. In addition to listed limitations, there are other implementation differences between database engines. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we be more specific here? And/or list things that we do support? |
||
|
|
||
| {{% alert color="warning" %}} | ||
| Always test usages of `DATEFORMAT` with the database engine on which your app runs. OQL queries with `DATEFORMAT` may return different results in HSQLDB and in the production database. | ||
| {{% /alert %}} | ||
|
|
||
| #### Examples{#oql-dateformat-example} | ||
|
|
||
| Let's assume that an object has an attribute `StartDate` of type Date and time with value `30 December 2025 13:02:15.300`. | ||
|
|
||
| | Function call | Result | Notes | | ||
| |--------------|------|-----| | ||
| | `DATEFORMAT(StartDate, 'dd MMM yyyy')` | 30 Dec 2025 | | | ||
| | `DATEFORMAT(StartDate, 'yyyy-MM-dd hh:mm:ss a')` | 2025-12-30 01:02:15 PM | | | ||
| | `DATEFORMAT(StartDate, 'EEE-ww-YYYY')` | Tue-01-2026 | ISO date format is not supported by SAP HANA and SQL Server. `w` stands for the ISO week number, and `Y` stands for ISO year. | | ||
|
|
||
| ### DATEPARSE {#dateparse-function} | ||
|
|
||
| The `DATEPARSE` function parses string values to Date and time using a specified pattern. | ||
|
|
@@ -1050,6 +1101,7 @@ When an OQL query is executed, `DATEPARSE` is converted to the corresponding dat | |
|
|
||
| 1. Format letters `u`, `F`, `G`, `k`, `K` are not supported. | ||
| 2. MySQL and MariaDB do not support format letters `S` and `W`. | ||
| 2. SAP HANA does not support format letters `Y` and `w`. | ||
| 3. For SQL Server, `DATEPARSE` accepts only patterns that match SQL Server styles 0 to 7, 9 to 13, 100 to 107, 109 to 113, 120 and 121. See [SQL Server documentation](https://learn.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql?view=sql-server-ver17#date-and-time-styles) for the list of supported styles. | ||
| 4. Format letter `h` accepts different ranges of values per database: | ||
|
|
||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and parameters