开发者

sql datetime format

I am trying to开发者_JAVA百科 convert a date into this format YYYY-MM-DD hh:mm:ss eg. 2007-01-05 23:00:00. But my SQL leaves the string unchanged, can somebody tell me what I am doing wrong?

select convert(varchar,'23/02/2008 00:00:00',120)


Try SELECT CONVERT(DATETIME, '23/02/2008 00:00:00'). All you're doing is converting a string into a string, which won't change anything.


your data type needs to be DATETIME, eg:

select convert(DATETIME, '23/02/2008 00:00:00', 120)


try this. Works for Transact-SQL.

select convert(datetime,'23/02/2008 00:00:00')

I hope it helps


maybe you're looking to do this:

CONVERT(varchar,'23/02/2008 00:00:00',100) 'yyyy-mm-dd hh:mm:ss'


select format(getdate(),'dd-MM-yyyy hh:mm tt')


Following is the syntax to achieve what you are looking for

SELECT CONVERT(VARCHAR(19), GETDATE(), 120)

To know more about the date formats see the link http://www.sql-server-helper.com/tips/date-formats.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜