-
Notifications
You must be signed in to change notification settings - Fork 771
Documentation for DATETRUNC #10756
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/datetrunc
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.
Open
Documentation for DATETRUNC #10756
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -981,6 +982,70 @@ 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 local time zone. It should be a string literal containing an IANA time zone. GMT offset time zones are not supported. | ||
|
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. I think it would be good to mention the option of using |
||
|
|
||
| #### 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 previos Sunday if date part type `WEEK` is used. | ||
|
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. Typo in previo[u]s. |
||
| {{% /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 | ||
|
|
||
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.
The phrase "local time zone" is used in many places, but I think it is unclear what that means. "user time zone" may be better, possibly with a link to https://docs.mendix.com/refguide/date-and-time-handling/.