How to Convert VarChar 'dd/mm/yy' to DateTime yyyy-mm-dd
Exp. Convert 31/12/04 to 2004-12-31Arief
DECLARE @.dt AS VARCHAR(20)
SET @.dt='31/12/04'
SELECT CAST(RTRIM(y*10000+m*100+d)AS DATETIME)
FROM
(
SELECT '20'+SUBSTRING(@.dt,7,2)AS y,
SUBSTRING(@.dt,4,2)AS m
,SUBSTRING(@.dt,1,2)AS d
) AS D
"Arief" <a_nursetyawan@.yahoo.com> wrote in message
news:1121409145.447241.152520@.o13g2000cwo.googlegroups.com...
> How to Convert VarChar 'dd/mm/yy' to DateTime yyyy-mm-dd
> Exp. Convert 31/12/04 to 2004-12-31
>|||Datetime data doesn't have any format, it is the client application that formats the data. If you
want to convert to datetime:
SELECT CONVERT(datetime, '23/07/98', 3)
And if you want above to be returned in some special format, you need to convert back to a string:
SELECT CONVERT(char(10), CONVERT(datetime, '23/07/98', 3), 120)
For more information, see:
http://www.karaszi.com/SQLServer/info_datetime.asp
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Arief" <a_nursetyawan@.yahoo.com> wrote in message
news:1121409145.447241.152520@.o13g2000cwo.googlegroups.com...
> How to Convert VarChar 'dd/mm/yy' to DateTime yyyy-mm-dd
> Exp. Convert 31/12/04 to 2004-12-31
>
Showing posts with label exp. Show all posts
Showing posts with label exp. Show all posts
Subscribe to:
Posts (Atom)