You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/en/docs/refguide/modeling/domain-model/oql/oql-expression-syntax.md
+44Lines changed: 44 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1022,6 +1022,50 @@ SELECT Revenue : DATEDIFF(MONTH, End, Start ) as avg_revenue FROM Sales.Period
1022
1022
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.
1023
1023
{{% /alert %}}
1024
1024
1025
+
### DATEPARSE {#dateparse-function}
1026
+
1027
+
The `DATEPARSE` function parses string values to Date and time using a specified pattern.
1028
+
1029
+
#### Syntax
1030
+
1031
+
The syntax is as follows:
1032
+
1033
+
```sql
1034
+
DATEPARSE ( expression , pattern )
1035
+
```
1036
+
1037
+
`expression` is a value of type String.
1038
+
1039
+
`pattern` is a pattern гыув to convert `expression` to a Date and time value. Only string literals are allowed.
1040
+
1041
+
#### Pattern syntax
1042
+
1043
+
`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).
1044
+
1045
+
#### Limitations and database-specific differences
1046
+
1047
+
When an OQL query is executed, `DATEPARSE` is converted to the corresponding database function. Due to implementation specifics of database engines, different limitations apply:
1048
+
1049
+
1. Format letters `u`, `F`, `G`, `k`, `K` are not supported.
1050
+
2. Additionally, format letters `S` and `W` are not supported in MySQL and MariaDB.
1051
+
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.
1052
+
4. Format letter `h` accepts different ranges of values per database:
1053
+
1. HSQLDB accepts values `0` to `11`
1054
+
2. Other databases accept values `1` to `12`
1055
+
5. In addition to listed limitations, there are other implementation differences between database engines.
1056
+
1057
+
{{% alert color="warning" %}}
1058
+
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.
1059
+
{{% /alert %}}
1060
+
1061
+
#### Examples{#oql-dateparse-example}
1062
+
1063
+
| Function call | Result | Notes |
1064
+
|--------------|------|-----|
1065
+
|`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. |
1066
+
|`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. |
1067
+
|`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. |
1068
+
1025
1069
### DATEPART {#datepart-function}
1026
1070
1027
1071
The `DATEPART` function retrieves a specified element from `DATETIME` values. The return type is `INTEGER`.
0 commit comments