将CHAR YYYYMMDD转换为mm / dd / yyyy [英] Convert CHAR YYYYMMDD to mm/dd/yyyy
问题描述
我似乎无法找到一种方法,将
YYYYMMDD形式的CHAR(8)列转换为实际日期,例如mm / dd / yyyy
有人能指出我正确的方向吗?
谢谢
更正INT类型中的源字段
那么如何将INT类型YYYYMMDD转换为日期mm / dd / yyyy
" rdraider" < rd ****** @ sbcglobal.netwrote in message
news:7U ***************** @ newssvr25.news.prodigy。 ne ...
>我似乎找不到以
YYYYMMDD形式转换CHAR(8)列的方法到实际日期,如mm / dd / yyyy
有人能指出我正确的方向吗?
谢谢
" rdraider" < rd ****** @ sbcglobal.netwrote in message
news:7U ***************** @ newssvr25.news.prodigy。 ne ...
>我似乎找不到以
YYYYMMDD形式转换CHAR(8)列的方法到实际日期,如mm / dd / yyyy
有人能指出我正确的方向吗?
谢谢
''YYYYMMDD''是SQL支持的标准非区域格式之一
Server。无需特殊转换:
DECLARE @dt CHAR(8);
SET @dt =''20070823'';
SELECT CAST(@dt AS DATETIME)AS dt;
dt
------------ ------------------------------------------
2007-08-23 00:00:00.000
(1排受影响)
-
David Portas ,SQL Server MVP
请尽可能发布足够的代码来重现您的问题。
包含CREATE TABLE和INSERT语句通常会有所帮助。
说明您正在使用的SQL Server版本,并指定任何错误消息的内容
。
SQL Server联机丛书:
< a rel =nofollowhref =http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx\"target =_ blank> http://msdn2.microsoft.com/ library / m ... S,SQL.90).aspx
-
" rdraider" < rd ****** @ sbcglobal.netwrote in message
news:5 _ ***************** @ newssvr25.news.prodigy。 ne ...
更正INT类型中的源字段
那么如何将INT类型YYYYMMDD转换为日期mm / dd / yyyy
DECLARE @dt INT;
SET @dt = 20070823;
SELECT CAST(CAST(@dt AS CHAR(8))AS DATETIME)AS dt;
-
David Portas,SQL Server MVP
只要有可能,请发布足够的代码来重现你的问题。
包含CREATE TABLE和INSERT语句通常会有所帮助。
陈述什么您正在使用的SQL Server版本,并指定任何错误消息的内容
。
SQL Server联机丛书:
http://msdn2.microsoft.com/library/m。 ..S,SQL.90).aspx
-
I can''t seem to find a method of converting a CHAR(8) column in the form of
YYYYMMDD to an actual date such as mm/dd/yyyy
Can anyone point me in the right direction?
Thanks解决方案Correction the source field in an INT type
So how to convert INT type YYYYMMDD to a date mm/dd/yyyy
"rdraider" <rd******@sbcglobal.netwrote in message
news:7U*****************@newssvr25.news.prodigy.ne t...>I can''t seem to find a method of converting a CHAR(8) column in the form of
YYYYMMDD to an actual date such as mm/dd/yyyy
Can anyone point me in the right direction?
Thanks
"rdraider" <rd******@sbcglobal.netwrote in message
news:7U*****************@newssvr25.news.prodigy.ne t...>I can''t seem to find a method of converting a CHAR(8) column in the form of
YYYYMMDD to an actual date such as mm/dd/yyyy
Can anyone point me in the right direction?
Thanks
''YYYYMMDD'' is one of the standard, non-regional formats supported by SQL
Server. No special conversion is necessary:
DECLARE @dt CHAR(8);
SET @dt = ''20070823'';
SELECT CAST(@dt AS DATETIME) AS dt;
dt
------------------------------------------------------
2007-08-23 00:00:00.000
(1 row(s) affected)
--
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/m...S,SQL.90).aspx
--
"rdraider" <rd******@sbcglobal.netwrote in message
news:5_*****************@newssvr25.news.prodigy.ne t...Correction the source field in an INT type
So how to convert INT type YYYYMMDD to a date mm/dd/yyyy
DECLARE @dt INT;
SET @dt = 20070823;
SELECT CAST(CAST(@dt AS CHAR(8)) AS DATETIME) AS dt;
--
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/m...S,SQL.90).aspx
--
这篇关于将CHAR YYYYMMDD转换为mm / dd / yyyy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!