ToDateTime

The ToDateTime function converts a string, date, or date time value to a date_time.

Syntax

ToDateTime(<String>|<date>|<offset_date_time>|<zoned_date_time>|<instant> [,<date_time_mask>])

Return Type

date_time

Details

Connect displays dates using the ISO 8601 date format, yyyy-MM-ddThh:mm:ss. Warning: Date_time does not contain UTC offset or time zone information. Beware when converting values of instant, offset_date_time, and zoned_date_time to date_time using this function, as they may contain UTC offset and time zone information.

The optional date_time_mask parameter is a Java 8 formatting mask that describes the first input parameter. For more information about formatting masks, see Java’s Class DateTimeFormatter documentation. The examples below show common use cases.

Examples

select Now() now_is_an_instant, ToDateTime(Now()) now_as_date_time from Empty();

todatetime_01

select CurDate(), ToDateTime(CurDate()) from Empty();

todatetime_02

select zoned_date_time_europe1, TypeNameOf(zoned_date_time_europe1),
ToDateTime(zoned_date_time_europe1), TypeNameOf(ToDateTime(zoned_date_time_europe1)) 
from AllTypes();

todatetime_03

select '2014-07-23T09:26:44' starting_val,
TypeNameOf('2014-07-23T09:26:44') as TypeNameOf_starting_val,
ToDateTime('2014-07-23T09:26:44','yyyy-MM-dd''T''HH:mm:ss') cast_to_date_time,
TypeNameOf(ToDateTime('2014-07-23T09:26:44','yyyy-MM-dd''T''HH:mm:ss')) as TypeNameOf_cast
from Empty();

todatetime_04

Related Functions

FormatDateTime

IsDateTimeFormat

ToDate

ToOffsetDateTime

ToZonedDateTime

TypeNameOf