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
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
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
    )