Presto SQL - 将日期字符串转换为日期格式 [英] Presto SQL - Converting a date string to date format

查看:312
本文介绍了Presto SQL - 将日期字符串转换为日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 presto 并且有一个日期格式为 varchar 看起来像 -

I'm on presto and have a date formatted as varchar that looks like -

7/14/2015 8:22:39 AM

我查看了 presto 文档并尝试了各种方法(转换、date_format、使用 split_part 解析然后转换),但没有将其转换为可以与 date_diff 等函数一起使用的日期格式.

I've looked the presto docs and tried various things(cast, date_format, using split_part to parse and then cast) and am not getting this to convert to a date format that I can use with functions like date_diff.

我试过了:

cast(fieldname as timestamp)
date_format(fieldname, '%Y-%m-%d %T)

两者都给我这样的错误

'Value cannot be cast to timestamp: 3/31/2016 6:05:04 PM'

如何转换?

推荐答案

我想通了.下面将其转换为 24 小时日期格式.

I figured it out. The below works in converting it to a 24 hr date format.

select date_parse('7/22/2016 6:05:04 PM','%m/%d/%Y %h:%i:%s %p')

请参阅 Presto 中的 date_parse 文档.

See date_parse documentation in Presto.

这篇关于Presto SQL - 将日期字符串转换为日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆