Skip to content

Commit 1d756d4

Browse files
committed
Documentation for DATEPARSE
1 parent 0fb4546 commit 1d756d4

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

content/en/docs/refguide/modeling/domain-model/oql/oql-expression-syntax.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,52 @@ SELECT Revenue : DATEDIFF(MONTH, End, Start ) as avg_revenue FROM Sales.Period
10221022
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.
10231023
{{% /alert %}}
10241024

1025+
### DATEPARSE {#dateparse-function}
1026+
1027+
The `DATEPARSE` function parses string values to Date and time using a specified pattern.
1028+
1029+
This function was introduced in Mendix version 11.10.0. It is currently supported only in Java actions.
1030+
1031+
#### Syntax
1032+
1033+
The syntax is as follows:
1034+
1035+
```sql
1036+
DATEPARSE ( expression , pattern )
1037+
```
1038+
1039+
`expression` is a value of type String.
1040+
1041+
`pattern` is a pattern гыув to convert `expression` to a Date and time value. Only string literals are allowed.
1042+
1043+
#### Pattern syntax
1044+
1045+
`DATEPARSE` 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).
1046+
1047+
#### Limitations and database-specific differences
1048+
1049+
When an OQL query is executed, `DATEPARSE` is converted to the corresponding database function. Due to implementation specifics of database engines, different limitations apply:
1050+
1051+
1. Format letters `u`, `F`, `G`, `k`, `K` are not supported.
1052+
2. Additionally, format letters `S` and `W` are not supported in MySQL and MariaDB.
1053+
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.
1054+
4. Format letter `h` accepts different ranges of values per database:
1055+
1. HSQLDB accepts values `0` to `11`
1056+
2. Other databases accept values `1` to `12`
1057+
5. In addition to listed limitations, there are other implementation differences between database engines.
1058+
1059+
{{% alert color="warning" %}}
1060+
Always test usages of `DATEPARSE` with the database engine on which your app runs. OQL queries with `DATEPARSE` may return different results in HSQLDB and in the production database.
1061+
{{% /alert %}}
1062+
1063+
#### Examples{#oql-dateparse-example}
1064+
1065+
| Function call | Result | Notes |
1066+
|--------------|------|-----|
1067+
| `DATEPARSE('20 Mar 2026', 'dd MMM yyyy')` | 2026-03-20 00:00:00.000 | This format works for all databases. It matches SQL Server style 102. |
1068+
| `DATEPARSE('2026-03-20 14:30:45', 'yyyy-MM-dd HH:mm:ss')` | 2026-03-20 14:30:45.000 | This format works for all databases. It matches SQL Server style 120. |
1069+
| `DATEPARSE('20/03/2026 14:30:45.123', 'dd/MM/yyyy HH:mm:ss.SSS')` | 2026-03-20 14:30:45.123 | This format does not work in MySQL and MariaDB due to unsupported letter `S`. It does not work in SQL Server because there is no matching datetime style. |
1070+
10251071
### DATEPART {#datepart-function}
10261072

10271073
The `DATEPART` function retrieves a specified element from `DATETIME` values. The return type is `INTEGER`.

0 commit comments

Comments
 (0)