From f52576eda9497c87e35cc7a0ef371e221ef40407 Mon Sep 17 00:00:00 2001 From: Pavel Antoshin Date: Fri, 13 Feb 2026 16:18:43 +0100 Subject: [PATCH 1/3] Document DATETRUNC --- .../domain-model/oql/oql-expression-syntax.md | 83 ++++++++++++++++++- 1 file changed, 80 insertions(+), 3 deletions(-) diff --git a/content/en/docs/refguide/modeling/domain-model/oql/oql-expression-syntax.md b/content/en/docs/refguide/modeling/domain-model/oql/oql-expression-syntax.md index 0702ea87d6b..041f6a2ce59 100644 --- a/content/en/docs/refguide/modeling/domain-model/oql/oql-expression-syntax.md +++ b/content/en/docs/refguide/modeling/domain-model/oql/oql-expression-syntax.md @@ -687,6 +687,7 @@ These are the currently supported functions: * COALESCE * DATEDIFF * DATEPART +* DATETRUNC * LENGTH * LOWER * RANGEBEGIN @@ -875,7 +876,7 @@ DATEDIFF ( unit , startdate_expression, enddate_expression [, timezone ] ) * `MINUTE`, * `SECOND` * `MILLISECOND`. - + For more information on `DATETIME` values, see the [example section under *DATEPART*](#oql-datepart-example), below. ##### startdate_expression @@ -888,7 +889,11 @@ For more information on `DATETIME` values, see the [example section under *DATEP ##### timezone -`timezone` specifies the time zone to use for the retrieval. This parameter is optional and defaults to the local time zone. It should be a string literal containing an [IANA time zone](https://www.iana.org/time-zones). GMT offset time zones are not supported. +`timezone` specifies the time zone to use for the retrieval. This parameter is optional and defaults to the user time zone. It should be a string literal containing an [IANA time zone](https://www.iana.org/time-zones). GMT offset time zones are not supported. + +{{% alert color="info" %}} +The user time zone is usually different from UTC. To get the result in the UTC time zone, explicitly specify `'UTC'` in this parameter. For details on time zone handling in Mendix Runtime, see [Date and Time Handling](/refguide/date-and-time-handling/). +{{% /alert %}} #### Examples @@ -953,7 +958,11 @@ DATEPART ( datepart , date_expression [, timezone ] ) ##### timezone -`timezone` specifies the time zone to use for the retrieval. This parameter is optional and defaults to the local time zone. It should be a string literal containing an IANA time zone. GMT offset time zones are not supported. +`timezone` specifies the time zone to use for the retrieval. This parameter is optional and defaults to the user time zone. It should be a string literal containing an IANA time zone. GMT offset time zones are not supported. + +{{% alert color="info" %}} +The user time zone is usually different from UTC. To get the result in the UTC time zone, explicitly specify `'UTC'` in this parameter. For details on time zone handling in Mendix Runtime, see [Date and Time Handling](/refguide/date-and-time-handling/). +{{% /alert %}} #### Examples{#oql-datepart-example} @@ -981,6 +990,74 @@ SELECT End FROM Sales.Period WHERE DATEPART(YEAR, End) = 2025 |---------------------| | 2025-07-05 00:00:00 | +### DATETRUNC {#datetrunc-function} + +The `DATETRUNC` function truncates a `DATETIME` value to a specified datepart. The return type is `DATETIME`. + +This function was introduced in Mendix version 11.9.0 + +#### Syntax + +The syntax is as follows: + +```sql +DATETRUNC ( datepart , date_expression [, timezone ] ) +``` + +##### datepart + +`datepart` specifies the part to which the `DATETIME` value is truncated. For possible values, see the [Example](#oql-datetrunc-example) below. + +##### date_expression + +`date_expression` specifies the date to retrieve an element from. The expression should resolve to a `DATETIME` value. String representations of `DATETIME` are accepted. + +##### timezone + +`timezone` specifies the time zone to use for truncation. This parameter is optional and defaults to the user time zone. It should be a string literal containing an IANA time zone. GMT offset time zones are not supported. + +{{% alert color="info" %}} +The user time zone is usually different from UTC. To get the result in the UTC time zone, explicitly specify `'UTC'` in this parameter. For details on time zone handling in Mendix Runtime, see [Date and Time Handling](/refguide/date-and-time-handling/). +{{% /alert %}} + +#### Examples{#oql-datetrunc-example} + +| datepart | Truncation result for `2005-09-03T16:34:20.356` | +|--------------|-------------------------------------------------| +| `YEAR` | `2005-01-01T00:00:00.000` | +| `QUARTER` | `2005-07-01T00:00:00.000` | +| `MONTH` | `2005-09-01T00:00:00.000` | +| `DAY` | `2005-09-03T00:00:00.000` | +| `WEEK`* | `2005-07-29T00:00:00.000` | +| `HOUR` | `2005-09-03T16:00:00.000` | +| `MINUTE` | `2005-09-03T16:34:00.000` | +| `SECOND` | `2005-09-03T16:34:20.000` | + +{{% alert color="info" %}} +Date part types `DAYOFYEAR`, `WEEKDAY` and `MILLISECOND` are not supported by the `DATETRUNC` function +{{% /alert %}} + +{{% alert color="info" %}} +For the date part type `WEEK`, the result of the `DATETRUNC` function depends on the database configuration. For example, by default, the first day of the week in MS SQL Server is Sunday, which means that dates are truncated to previous Sunday if date part type `WEEK` is used. +{{% /alert %}} + +`DATETRUNC` function can be used to group data by time periods: + +```sql +SELECT + DATETRUNC(QUARTER, End) AS PeriodEndQuarter, + SUM(Revenue) AS QuarterPeriodRevenue +FROM + Sales.Period +GROUP BY + DATETRUNC(QUARTER, End) +``` + +| PeriodEndQuarter | QuarterPeriodRevenue | +|---------------------|----------------------| +| 2024-04-01 00:00:00 | 10 | +| 2025-07-01 00:00:00 | 28 | + ### LENGTH {#length-function} #### Description From 444001468a0513344a2e791fd4937659a247816c Mon Sep 17 00:00:00 2001 From: MarkvanMents Date: Tue, 24 Feb 2026 14:37:41 +0100 Subject: [PATCH 2/3] Proofread --- .../modeling/domain-model/oql/oql-expression-syntax.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/content/en/docs/refguide/modeling/domain-model/oql/oql-expression-syntax.md b/content/en/docs/refguide/modeling/domain-model/oql/oql-expression-syntax.md index 041f6a2ce59..f753e350287 100644 --- a/content/en/docs/refguide/modeling/domain-model/oql/oql-expression-syntax.md +++ b/content/en/docs/refguide/modeling/domain-model/oql/oql-expression-syntax.md @@ -950,7 +950,7 @@ DATEPART ( datepart , date_expression [, timezone ] ) ##### datepart -`datepart` specifies the part of the `DATETIME` value to retrieve. For possible values, see the [Example](#oql-datepart-example) below. +`datepart` specifies the part of the `DATETIME` value to retrieve. For possible values, see [Examples](#oql-datepart-example), below. ##### date_expression @@ -1006,7 +1006,7 @@ DATETRUNC ( datepart , date_expression [, timezone ] ) ##### datepart -`datepart` specifies the part to which the `DATETIME` value is truncated. For possible values, see the [Example](#oql-datetrunc-example) below. +`datepart` specifies the part to which the `DATETIME` value is truncated. For possible values, see [Examples](#oql-datetrunc-example), below. ##### date_expression @@ -1041,7 +1041,7 @@ Date part types `DAYOFYEAR`, `WEEKDAY` and `MILLISECOND` are not supported by th For the date part type `WEEK`, the result of the `DATETRUNC` function depends on the database configuration. For example, by default, the first day of the week in MS SQL Server is Sunday, which means that dates are truncated to previous Sunday if date part type `WEEK` is used. {{% /alert %}} -`DATETRUNC` function can be used to group data by time periods: +The `DATETRUNC` function can be used to group data by time periods: ```sql SELECT From df003e004ff39144042c6ee7d71c190e321e3d61 Mon Sep 17 00:00:00 2001 From: Pavel Antoshin Date: Tue, 24 Feb 2026 15:01:15 +0100 Subject: [PATCH 3/3] Fix a typo --- .../refguide/modeling/domain-model/oql/oql-expression-syntax.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/en/docs/refguide/modeling/domain-model/oql/oql-expression-syntax.md b/content/en/docs/refguide/modeling/domain-model/oql/oql-expression-syntax.md index f753e350287..3fccf020fd2 100644 --- a/content/en/docs/refguide/modeling/domain-model/oql/oql-expression-syntax.md +++ b/content/en/docs/refguide/modeling/domain-model/oql/oql-expression-syntax.md @@ -1028,7 +1028,7 @@ The user time zone is usually different from UTC. To get the result in the UTC t | `QUARTER` | `2005-07-01T00:00:00.000` | | `MONTH` | `2005-09-01T00:00:00.000` | | `DAY` | `2005-09-03T00:00:00.000` | -| `WEEK`* | `2005-07-29T00:00:00.000` | +| `WEEK`* | `2005-08-29T00:00:00.000` | | `HOUR` | `2005-09-03T16:00:00.000` | | `MINUTE` | `2005-09-03T16:34:00.000` | | `SECOND` | `2005-09-03T16:34:20.000` |