diff --git a/bigframes/core/compile/sqlglot/expressions/datetime_ops.py b/bigframes/core/compile/sqlglot/expressions/datetime_ops.py index a1c70262d5..21f8b39e7d 100644 --- a/bigframes/core/compile/sqlglot/expressions/datetime_ops.py +++ b/bigframes/core/compile/sqlglot/expressions/datetime_ops.py @@ -371,7 +371,12 @@ def _(expr: TypedExpr, op: ops.ToDatetimeOp) -> sge.Expression: ) return sge.Cast(this=result, to="DATETIME") - if expr.dtype in (dtypes.STRING_DTYPE, dtypes.TIMESTAMP_DTYPE): + if expr.dtype in ( + dtypes.STRING_DTYPE, + dtypes.TIMESTAMP_DTYPE, + dtypes.DATETIME_DTYPE, + dtypes.DATE_DTYPE, + ): return sge.TryCast(this=expr.expr, to="DATETIME") value = expr.expr @@ -396,7 +401,12 @@ def _(expr: TypedExpr, op: ops.ToTimestampOp) -> sge.Expression: "PARSE_TIMESTAMP", sge.convert(op.format), expr.expr, sge.convert("UTC") ) - if expr.dtype in (dtypes.STRING_DTYPE, dtypes.DATETIME_DTYPE): + if expr.dtype in ( + dtypes.STRING_DTYPE, + dtypes.DATETIME_DTYPE, + dtypes.TIMESTAMP_DTYPE, + dtypes.DATE_DTYPE, + ): return sge.func("TIMESTAMP", expr.expr) value = expr.expr