Skip to content

daft.functions.make_timestamp#

make_timestamp #

make_timestamp(year: Expression, month: Expression, day: Expression, hour: Expression, minute: Expression, second: Expression, timezone: str | None = None) -> Expression

Creates a timestamp from individual date/time components.

The second parameter accepts fractional values for sub-second precision. Invalid component combinations return null.

Parameters:

Name Type Description Default
year Expression

integer expression for the year.

required
month Expression

integer expression for the month (1-12).

required
day Expression

integer expression for the day (1-31).

required
hour Expression

integer expression for the hour (0-23).

required
minute Expression

integer expression for the minute (0-59).

required
second Expression

numeric expression for the second (0-59, may include fractional part).

required
timezone str | None

optional timezone string (e.g. "UTC"). When provided the returned timestamp carries this timezone metadata.

None

Returns:

Name Type Description
Expression Expression

a Timestamp(microseconds) expression.

Examples:

1
2
3
>>> import daft
>>> from daft.functions import make_timestamp
>>> make_timestamp(daft.col("y"), daft.col("m"), daft.col("d"), daft.col("h"), daft.col("mi"), daft.col("s"))
make_timestamp(col(y), col(m), col(d), col(h), col(mi), col(s))
Source code in daft/functions/datetime.py
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
def make_timestamp(
    year: Expression,
    month: Expression,
    day: Expression,
    hour: Expression,
    minute: Expression,
    second: Expression,
    timezone: str | None = None,
) -> Expression:
    """Creates a timestamp from individual date/time components.

    The ``second`` parameter accepts fractional values for sub-second precision.
    Invalid component combinations return null.

    Args:
        year: integer expression for the year.
        month: integer expression for the month (1-12).
        day: integer expression for the day (1-31).
        hour: integer expression for the hour (0-23).
        minute: integer expression for the minute (0-59).
        second: numeric expression for the second (0-59, may include fractional part).
        timezone: optional timezone string (e.g. ``"UTC"``). When provided the
            returned timestamp carries this timezone metadata.

    Returns:
        Expression: a Timestamp(microseconds) expression.

    Examples:
        >>> import daft
        >>> from daft.functions import make_timestamp
        >>> make_timestamp(daft.col("y"), daft.col("m"), daft.col("d"), daft.col("h"), daft.col("mi"), daft.col("s"))
        make_timestamp(col(y), col(m), col(d), col(h), col(mi), col(s))
    """
    year = Expression._to_expression(year)
    month = Expression._to_expression(month)
    day = Expression._to_expression(day)
    hour = Expression._to_expression(hour)
    minute = Expression._to_expression(minute)
    second = Expression._to_expression(second)
    return Expression._call_builtin_scalar_fn(
        "make_timestamp", year, month, day, hour, minute, second, timezone=timezone
    )