[英]Convert 8 Digit Number into Date in SQL
I have a date field that is pulling from a server as just an 8 digit number, and I would like to convert it to a standard date format. 我有一个从服务器提取的日期字段,只是一个8位数字,我想将其转换为标准日期格式。
For example, " 20140501
" would be converted to 05-01-2014
例如,“
20140501
”将转换为05-01-2014
I tried using the DateTime
code, but that didn't work for me. 我尝试使用
DateTime
代码,但这对我不起作用。 Any suggestions? 有什么建议么?
Many databases might recognize the string '20140501' as a date, because this is an ISO standard format. 许多数据库可能会将字符串“ 20140501”识别为日期,因为这是一种ISO标准格式。 Hence, you might try this:
因此,您可以尝试以下操作:
select cast(cast(datecol as varchar(255)) as date)
Whether or not this works depends on your database. 是否有效取决于您的数据库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.