Use parse_datetime
and format_datetime
along with the proper formatting elements.
-- get a datetime
select parse_datetime(
'%m/%d/%Y %T %p',
'4/25/2016 09:37:35 AM'
)
;
-- 2016-04-25T09:37:35 (string representation)
Note that a datetime
doesn't have a timezone. To include a timezone, you would use timestamp
.
-- get a timestamp
select parse_timestamp(
'%m/%d/%Y %T %p',
'4/25/2016 09:37:35 AM',
'UTC'
)
;
-- 2016-04-25 09:37:35 UTC (string representation)
-- get the string representation you specified
select format_timestamp(
'%F %T %Z',
parse_timestamp(
'%m/%d/%Y %T %p',
'4/25/2016 09:37:35 AM',
'UTC'
)
)
;
-- 2016-04-25 09:37:35 UTC