Skip to content

daft.functions.convert_time_zone#

convert_time_zone #

convert_time_zone(expr: Expression, to_timezone: str, from_timezone: str | None = None) -> Expression

Converts a timestamp to another timezone while preserving the instant in time.

If the timestamp has no timezone, from_timezone must be provided to interpret the local time before converting to to_timezone.

Parameters:

Name Type Description Default
expr Expression

Timestamp expression to convert.

required
to_timezone str

Target timezone (e.g. "UTC", "+02:00", "America/New_York").

required
from_timezone str | None

Source timezone for timestamps without a timezone.

None

Returns:

Name Type Description
Expression Expression

Timestamp expression with the target timezone.

Source code in daft/functions/datetime.py
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
def convert_time_zone(expr: Expression, to_timezone: str, from_timezone: str | None = None) -> Expression:
    """Converts a timestamp to another timezone while preserving the instant in time.

    If the timestamp has no timezone, `from_timezone` must be provided to interpret the local time before converting to `to_timezone`.

    Args:
        expr: Timestamp expression to convert.
        to_timezone: Target timezone (e.g. "UTC", "+02:00", "America/New_York").
        from_timezone: Source timezone for timestamps without a timezone.

    Returns:
        Expression: Timestamp expression with the target timezone.
    """
    return Expression._call_builtin_scalar_fn("convert_time_zone", expr, to_timezone, from_timezone)