简体   繁体   English

在SQL中以YYYY-MM-DD HH:MM:SS格式转换日期和时间字符串

[英]Convert a date and time string in the format YYYY-MM-DD HH:MM:SS in SQL

Is there any way to convert "A date and time string in the format YYYY-MM-DD HH:MM:SS” using legacy SQL syntax or standard SQL syntax in BigQuery. 有什么方法可以使用BigQuery中的旧版SQL语法或标准SQL语法转换“格式为YYYY-MM-DD HH:MM:SS的日期和时间字符串”。

For eg. 例如。 "November 9, 2017" to 2017-11-09 00:00:00 “ 2017年11月9日”至2017-11-09 00:00:00

Below is for BigQuery Standard SQL 以下是BigQuery标准SQL

#standardSQL
SELECT PARSE_DATE('%B %d, %Y', 'November 9, 2017')

result is 结果是

f0_  
2017-11-09   

or you can use 或者你可以使用

#standardSQL
SELECT PARSE_DATETIME('%B %d, %Y', 'November 9, 2017') 

which returns 哪个返回

f0_  
2017-11-09T00:00:00  

SQL Server (2005, 2000, 7.0) does not have any flexible, or even non-flexible, way of taking an arbitrarily structured datetime in string format and converting it to the datetime data type. SQL Server(2005、2000、7.0)没有任何灵活的甚至不灵活的方式来获取字符串格式的任意结构化datetime并将其转换为datetime数据类型。

By "arbitrarily", I mean "a form that the person who wrote it, though perhaps not you or I or someone on the other side of the planet, would consider to be intuitive and completely obvious." “任意”是指“一种形式,尽管也许不是您或我或地球另一端的人,但是撰写它的人会认为它是直观且完全显而易见的。” Frankly, I'm not sure there is any such algorithm. 坦白说,我不确定是否有这样的算法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试以(yyyy-mm-dd hh:mm:ss)日期格式转换字符串格式(dd-mm-yyyy hh:mm:ss) - Trying to convert string format (dd-mm-yyyy hh:mm:ss) in (yyyy-mm-dd hh:mm:ss) date format 在SQL中以YYYY-MM-DD HH:MM:SS格式转换日期,日期和时间戳记字符串 - Convert a day, date and timestamp string in the format YYYY-MM-DD HH:MM:SS in SQL pyspark sql 将日期格式从 mm/dd/yy hh:mm 或 yyyy-mm-dd hh:mm:ss 转换为 yyyy-mm-dd hh:mm 格式 - pyspark sql convert date format from mm/dd/yy hh:mm or yyyy-mm-dd hh:mm:ss into yyyy-mm-dd hh:mm format 以yyyy-MM-dd HH:mm:ss“格式转换日期时间 - Convert the date time in yyyy-MM-dd HH:mm:ss" format 在雅典娜中将 yyyymm 字符串转换为 yyyy-mm-dd hh:mm:ss 日期时间 - Convert yyyymm String to yyyy-mm-dd hh:mm:ss date time in athena 如何将mm / dd / yyyy格式的日期转换为yyyy-mm-dd hh:mi:ss.mmm - How to convert date in mm/dd/yyyy format to yyyy-mm-dd hh:mi:ss.mmm 将时间从{yyyy-mm-dd hh:mm:ss}转换为{yyyy-mm-dd hh} - CONVERT Time from {yyyy-mm-dd hh:mm:ss} to {yyyy-mm-dd hh} 在yql中将yyyy-mm-dd hh:mm:ss转换为yyyy-mm-dd - convert yyyy-mm-dd hh:mm:ss to yyyy-mm-dd in sql 将日期格式SQL转换为YYYY-MM-DD HH:MM:SS - Converting Date Format SQL to YYYY-MM-DD HH:MM:SS 将日期时间“ YYYY-MM-DD HH:mm:ss”转换为“ DD / MM / YYYY HH:mm:ss” - convert Datetime 'YYYY-MM-DD HH:mm:ss' to 'DD/MM/YYYY HH:mm:ss'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM