简体   繁体   中英

SQL Server Varchar to Datetime conversion

I have a varchar representing a datetime in this form :

dd-MM-yyyy HH:MI:SS AM    

How can I convert it to datetime type ?

I have checked the list of standards of datetime here But I see no corresponding one to my format above.

Cast it directly

select CAST('10-02-2014 05:10:22 AM ' AS DATETIME)

Try this too..

 select CONVERT(varchar(15),GETDATE(),105)+' '+CONVERT(varchar(30),CONVERT(VARCHAR,GETDATE(),108))+' '+SUBSTRING(CONVERT(varchar(30),CONVERT(VARCHAR,GETDATE(),100)),18,2)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM