- Categories:
AS_DATE¶
Casts aVARIANT value to aDATE value. This function doesnot convert values ofother data types, including timestamps, to DATE values.
- See also:
Syntax¶
AS_DATE(<variant_expr>)
Copy
Arguments¶
variant_expr
An expression that evaluates to a value of type VARIANT.
Returns¶
The function returns a value of type DATE or NULL:
If the type of the value in the
variant_expr
argument is DATE, the function returns a value of type DATE.
If the type of the value in the
variant_expr
argument doesn’t match the type of the outputvalue, the function returns NULL.If the
variant_expr
argument is NULL, the function returns NULL.
Examples¶
Create a table and load data into it:
CREATEORREPLACETABLEas_date_example(date1VARIANT);INSERTINTOas_date_example(date1)SELECTTO_VARIANT(TO_DATE('2024-10-10'));
Copy
Use the AS_DATE function in a query to cast a VARIANT value to a DATE value:
SELECTAS_DATE(date1)date_valueFROMas_date_example;
Copy
+------------+| DATE_VALUE ||------------|| 2024-10-10 |+------------+