daft.functions.date_trunc#
date_trunc #
date_trunc(interval: str, expr: Expression, relative_to: Expression | None = None) -> Expression
Truncates the datetime column to the specified interval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interval | str | The interval to truncate to. Must be a string representing a valid interval in "{integer} {unit}" format, e.g. "1 day". Valid time units are: 'microsecond', 'millisecond', 'second', 'minute', 'hour', 'day', 'week'. | required |
expr | Expression | The datetime expression to truncate. | required |
relative_to | optional | Timestamp to truncate relative to. If not provided, truncates to the start of the Unix epoch: 1970-01-01 00:00:00. | None |
Returns:
| Name | Type | Description |
|---|---|---|
Expression | Expression | a DateTime expression truncated to the specified interval |
Examples:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
╭─────────────────────┬─────────────────────╮
│ datetime ┆ truncated │
│ --- ┆ --- │
│ Timestamp[us] ┆ Timestamp[us] │
╞═════════════════════╪═════════════════════╡
│ 2021-01-01 00:01:01 ┆ 2021-01-01 00:01:00 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 2021-01-01 00:01:59 ┆ 2021-01-01 00:01:00 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 2021-01-01 00:02:00 ┆ 2021-01-01 00:02:00 │
╰─────────────────────┴─────────────────────╯
(Showing first 3 of 3 rows) Source code in daft/functions/datetime.py
1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 | |