Skip to content

daft.functions.day_of_month#

day_of_month #

day_of_month(expr: Expression) -> Expression

Retrieves the day of the month for a datetime column.

Returns:

Name Type Description
Expression Expression

a UInt32 expression with just the day_of_month extracted from a datetime column

Examples:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
>>> import datetime
>>> import daft
>>> from daft.functions import day_of_month
>>> df = daft.from_pydict(
...     {
...         "datetime": [
...             datetime.datetime(2024, 1, 1, 0, 0, 0),
...             datetime.datetime(2024, 2, 1, 0, 0, 0),
...             datetime.datetime(2024, 12, 31, 0, 0, 0),
...             datetime.datetime(2023, 12, 31, 0, 0, 0),
...         ],
...     }
... )
>>> df.with_column("day_of_month", day_of_month(df["datetime"])).collect()
╭─────────────────────┬──────────────╮
│ datetime            ┆ day_of_month │
│ ---                 ┆ ---          │
│ Timestamp[us]       ┆ UInt32       │
╞═════════════════════╪══════════════╡
│ 2024-01-01 00:00:00 ┆ 1            │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 2024-02-01 00:00:00 ┆ 1            │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 2024-12-31 00:00:00 ┆ 31           │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 2023-12-31 00:00:00 ┆ 31           │
╰─────────────────────┴──────────────╯
(Showing first 4 of 4 rows)
Source code in daft/functions/datetime.py
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
def day_of_month(expr: Expression) -> Expression:
    """Retrieves the day of the month for a datetime column.

    Returns:
        Expression: a UInt32 expression with just the day_of_month extracted from a datetime column

    Examples:
        >>> import datetime
        >>> import daft
        >>> from daft.functions import day_of_month
        >>> df = daft.from_pydict(
        ...     {
        ...         "datetime": [
        ...             datetime.datetime(2024, 1, 1, 0, 0, 0),
        ...             datetime.datetime(2024, 2, 1, 0, 0, 0),
        ...             datetime.datetime(2024, 12, 31, 0, 0, 0),
        ...             datetime.datetime(2023, 12, 31, 0, 0, 0),
        ...         ],
        ...     }
        ... )
        >>> df.with_column("day_of_month", day_of_month(df["datetime"])).collect()
        ╭─────────────────────┬──────────────╮
        │ datetime            ┆ day_of_month │
        │ ---                 ┆ ---          │
        │ Timestamp[us]       ┆ UInt32       │
        ╞═════════════════════╪══════════════╡
        │ 2024-01-01 00:00:00 ┆ 1            │
        ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
        │ 2024-02-01 00:00:00 ┆ 1            │
        ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
        │ 2024-12-31 00:00:00 ┆ 31           │
        ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
        │ 2023-12-31 00:00:00 ┆ 31           │
        ╰─────────────────────┴──────────────╯
        <BLANKLINE>
        (Showing first 4 of 4 rows)
    """
    return Expression._call_builtin_scalar_fn("day_of_month", expr)