Skip to content

Commit c4e5c05

Browse files
committed
DS-15648: Document further date/time function additions to the WAE SQL API
These are some assorted functions commonly used by LLMs: - `toDayOfWeek` - `toStartOfWeek` - `toStartOfTenMinutes` - `toStartOfFiveMinutes` - `toYYYYMM`
1 parent e26eaeb commit c4e5c05

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

src/content/docs/analytics/analytics-engine/sql-reference/date-time-functions.mdx

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,31 @@ Examples:
120120
toMonth(toDateTime('2025-10-27 00:00:00'))
121121
```
122122

123+
## toDayOfWeek <Badge text="New" variant="tip" size="small" />
124+
125+
Usage:
126+
127+
```sql
128+
toDayOfWeek(<datetime>)
129+
```
130+
131+
`toDayOfWeek` takes a datetime and returns its numerical day of the week.
132+
133+
Returns `1` to indicate Monday, `2` to indicate Tuesday, and so on.
134+
135+
Examples:
136+
137+
```sql
138+
-- returns the number 1 for Monday 27th October 2025
139+
toDayOfWeek(toDateTime('2025-10-27 00:00:00'))
140+
141+
-- returns the number 2 for Tuesday 28th October 2025
142+
toDayOfWeek(toDateTime('2025-10-28 00:00:00'))
143+
144+
-- returns the number 7 for Sunday 2nd November 2025
145+
toDayOfWeek(toDateTime('2025-11-02 00:00:00'))
146+
```
147+
123148
## toDayOfMonth <Badge text="New" variant="tip" size="small" />
124149

125150
Usage:
@@ -270,6 +295,29 @@ Examples:
270295
toStartOfMonth(toDateTime('2025-10-27 00:00:00'))
271296
```
272297

298+
## toStartOfWeek <Badge text="New" variant="tip" size="small" />
299+
300+
Usage:
301+
302+
```sql
303+
toStartOfWeek(<datetime>)
304+
```
305+
306+
`toStartOfWeek` rounds down a datetime to the start of the week. This can be useful
307+
for grouping data into equal-sized time ranges.
308+
309+
Treats Monday as the first day of the week.
310+
311+
Examples:
312+
313+
```sql
314+
-- round a time on a Monday down to Monday 2025-10-27 00:00:00
315+
toStartOfWeek(toDateTime('2025-10-27 00:00:00'))
316+
317+
-- round a time on a Wednesday down to Monday 2025-10-27 00:00:00
318+
toStartOfWeek(toDateTime('2025-10-29 00:00:00'))
319+
```
320+
273321
## toStartOfDay <Badge text="New" variant="tip" size="small" />
274322

275323
Usage:
@@ -324,6 +372,42 @@ Examples:
324372
toStartOfFifteenMinutes(toDateTime('2025-10-27 16:55:25'))
325373
```
326374

375+
## toStartOfTenMinutes <Badge text="New" variant="tip" size="small" />
376+
377+
Usage:
378+
379+
```sql
380+
toStartOfTenMinutes(<datetime>)
381+
```
382+
383+
`toStartOfTenMinutes` rounds down a datetime to the nearest ten minutes. This can be useful
384+
for grouping data into equal-sized time ranges.
385+
386+
Examples:
387+
388+
```sql
389+
-- round a timestamp down to 2025-10-27 16:50:00
390+
toStartOfTenMinutes(toDateTime('2025-10-27 16:55:25'))
391+
```
392+
393+
## toStartOfFiveMinutes <Badge text="New" variant="tip" size="small" />
394+
395+
Usage:
396+
397+
```sql
398+
toStartOfFiveMinutes(<datetime>)
399+
```
400+
401+
`toStartOfFiveMinutes` rounds down a datetime to the nearest five minutes. This can be useful
402+
for grouping data into equal-sized time ranges.
403+
404+
Examples:
405+
406+
```sql
407+
-- round a timestamp down to 2025-10-27 16:55:00
408+
toStartOfFiveMinutes(toDateTime('2025-10-27 16:55:25'))
409+
```
410+
327411
## toStartOfMinute <Badge text="New" variant="tip" size="small" />
328412

329413
Usage:
@@ -341,3 +425,21 @@ Examples:
341425
-- round a timestamp down to 2025-10-27 16:55:00
342426
toStartOfMinute(toDateTime('2025-10-27 16:55:25'))
343427
```
428+
429+
## toYYYYMM <Badge text="New" variant="tip" size="small" />
430+
431+
Usage:
432+
433+
```sql
434+
toYYYYMM(<datetime>)
435+
```
436+
437+
`toYYYYMM` returns a number representing year and month of a datetime.
438+
For instance a datetime on `2025-05-03` would return the number `202505`.
439+
440+
Examples:
441+
442+
```sql
443+
-- returns the number 202510
444+
toYYYYMM(toDateTime('2025-10-27 16:55:25'))
445+
```

0 commit comments

Comments
 (0)