SQL Server Convert Varchar to Datetime

2019-01-04 13:00发布

I have this date format: 2011-09-28 18:01:00 (in varchar), and I want to convert it to datetime changing to this format 28-09-2011 18:01:00. How can I do it?

9条回答
叼着烟拽天下
2楼-- · 2019-01-04 13:20

You can have all the different styles to datetime conversion :

http://www.w3schools.com/sql/func_convert.asp

This has range of values :-

CONVERT(data_type(length),expression,style)

For style values,
Choose anyone you need like I needed 106.

With all the existing my answer has a specific link to the help site so that even a beginner can refer to. That's how more useful

查看更多
ゆ 、 Hurt°
3楼-- · 2019-01-04 13:25

Like this

DECLARE @date DATETIME
SET @date = '2011-09-28 18:01:00'
select convert(varchar, @date,105) + ' ' + convert(varchar, @date,108)
查看更多
爷的心禁止访问
4楼-- · 2019-01-04 13:26
SELECT CONVERT(VARCHAR(10), GETDATE(), 105) + ' ' + CONVERT(VARCHAR(10), GETDATE(), 108)
查看更多
登录 后发表回答