Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to convert a varchar to a yyyy-mm-dd datetime?

Author  Topic 

zeeshan13
Constraint Violating Yak Guru

347 Posts

Posted - 2008-05-27 : 15:00:32
Hi All,

I have a table called Table1 with a field Date (varchar type). The records are like this;

05/21/08
07/02/08
06/04/08
06/10/08


I want to convert the above into datetime (yyyy-mm-dd format)....in the above example my output should be;

2008-05-21
2008-07-02
2008-06-04
2008-06-10

How can i do this?

Please help.

Zee...

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-05-27 : 15:01:46
You can use the CONVERT function with the appropriate style. But you should be doing this in your application rather than in T-SQL.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Database maintenance routines:
http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
Go to Top of Page

zeeshan13
Constraint Violating Yak Guru

347 Posts

Posted - 2008-05-27 : 16:36:55
OK. Thanks.....
Go to Top of Page
   

- Advertisement -