Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
DATETIME_TRUNC
Kürzt ein Datum auf die angegebene Granularität.
Verwendungsbeispiel
DATETIME_TRUNC(Order Date, MONTH)
Syntax
DATETIME_TRUNC( date_expression, part )
Parameter
date_expression: Ein Feld oder Ausdruck vom Typ „Datum“ oder „Datum und Uhrzeit“.
part: Die Zeitkomponente, die zurückgegeben werden soll. DATETIME_TRUNC unterstützt die folgenden Zeitkomponenten:
MICROSECOND: Verfügbar für Felder und Ausdrücke vom Typ „Datum und Uhrzeit“.
MILLISECOND: Verfügbar für Felder und Ausdrücke vom Typ „Datum und Uhrzeit“.
SECOND: Verfügbar für Felder und Ausdrücke vom Typ „Datum und Uhrzeit“.
MINUTE: Verfügbar für Felder und Ausdrücke vom Typ „Datum und Uhrzeit“.
HOUR: Verfügbar für Felder und Ausdrücke vom Typ „Datum und Uhrzeit“.
DAY
WEEK: Dieser Datumsteil beginnt mit Sonntag.
ISOWEEK: Verwendet Wochengrenzen nach ISO 8601. ISO-Wochen beginnen mit Montag.
MONTH
QUARTER
YEAR
ISOYEAR: Verwendet die Jahresgrenze gemäß der ISO 8601-Wochennummerierung. Die ISO-Jahresgrenze ist der Montag der ersten Woche, in der der Donnerstag in das entsprechende gregorianische Kalenderjahr fällt.
Im folgenden Beispiel liegt der ursprüngliche date_expression im gregorianischen Kalenderjahr 2015. DATE_TRUNC mit dem Datumsteil ISOYEAR kürzt date_expression jedoch bis zum Anfang des ISO-Jahres und nicht des gregorianischen Kalenderjahres. Der erste Donnerstag des Kalenderjahres 2015 fiel auf den 01.01.2015. Deshalb beginnt das ISO-Jahr 2015 mit dem Montag davor am 29.12.2014. Entsprechend fällt die ISO-Jahresgrenze vor dem date_expression 15.06.2015 auf den 29.12.2014.
Beispielformel
Ausgabe
DATE_TRUNC('2015-06-15', ISOYEAR)
2014-12-29
EXTRACT(ISOYEAR FROM DATETIME '2015-06-15')
2015
Hinweise
Diese Funktion ist für Datumstypen im Kompatibilitätsmodus nicht verfügbar.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-07-30 (UTC)."],[],[],null,["DATETIME_TRUNC\n==============\n\nTruncates a date to the specified granularity.\n\nSample usage\n------------\n\n`DATETIME_TRUNC(Order Date, MONTH)`\n\nSyntax\n------\n\n`DATETIME_TRUNC( `\u003cvar translate=\"no\"\u003edate_expression\u003c/var\u003e`, `\u003cvar translate=\"no\"\u003epart\u003c/var\u003e` )`\n\n### Parameters\n\n\u003cvar translate=\"no\"\u003edate_expression\u003c/var\u003e - a Date or a Date \\& Time field or expression.\n\n\u003cvar translate=\"no\"\u003epart\u003c/var\u003e - the time part to return. `DATETIME_TRUNC` supports the following time parts:\n\n- `MICROSECOND`: available for Date \\& Time fields or expressions.\n- `MILLISECOND`: available for Date \\& Time fields or expressions.\n- `SECOND`: available for Date \\& Time fields or expressions.\n- `MINUTE`: available for Date \\& Time fields or expressions.\n- `HOUR`: available for Date \\& Time fields or expressions.\n- `DAY`\n- `WEEK`: This date part begins on Sunday.\n- `ISOWEEK`: Uses [ISO 8601 week](https://en.wikipedia.org/wiki/ISO_week_date) boundaries. ISO weeks begin on Monday.\n- `MONTH`\n- `QUARTER`\n- `YEAR`\n- `ISOYEAR`: Uses the [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) week-numbering year boundary. The ISO year boundary is the Monday of the first week whose Thursday belongs to the corresponding Gregorian calendar year.\n\nReturn data type\n----------------\n\nDate \\& Time\n\nExamples\n--------\n\nIn the following example, the original date_expression is in the Gregorian calendar year 2015. However, DATE_TRUNC with the ISOYEAR date part truncates the date_expression to the beginning of the ISO year, not the Gregorian calendar year. The first Thursday of the 2015 calendar year was 2015-01-01, so the ISO year 2015 begins on the preceding Monday, 2014-12-29. Therefore the ISO year boundary preceding the date_expression 2015-06-15 is 2014-12-29.\n\nNotes\n-----\n\nThis function is not available for compatibility mode date types.\n\nRelated resources\n-----------------\n\n- [Dates and times](/looker/docs/studio/dates-and-times)\n- [Calculated fields](/looker/docs/studio/about-calculated-fields)\n- [Looker Studio function list](/looker/docs/studio/function-list)"]]