转换datetime sql [英] converting datetime sql

查看:67
本文介绍了转换datetime sql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此查询显示日期时间,我只想使用此但问题是它提供24小时格式的时间,如16:30,17:55,但我想使用12小时格式,如$; 30, 05:55

i am using this query to display datetime and i only want to use this but problem is that it gives times in 24 hours format like 16:30, 17:55 but i want to use 12 hours format like $;30, 05:55

SELECT [ID],REPLACE(convert(varchar, ReceivedMessages.ReceivedDateTime, 113), ' ','/') as RecievingDate FROM [CmsSMSDb].[dbo].[ReceivedMessages]

推荐答案

; 30,05:55

;30, 05:55
SELECT [ID],REPLACE(convert(varchar, ReceivedMessages.ReceivedDateTime, 113), ' ','/') as RecievingDate FROM [CmsSMSDb].[dbo].[ReceivedMessages]


113告诉转换使用24小时格式。

如果如果您使用109,您将获得12小时格式的上午/下午。



有关详细信息,请参阅此链接:



http://msdn.microsoft.com/en-us/library/ms187928.aspx [ ^ ]
The 113 tells the convert to use a 24 hour format.
If you use 109, you will get a 12 hour format with AM/PM.

See this link for further details:

http://msdn.microsoft.com/en-us/library/ms187928.aspx[^]


SELECT REPLACE(SUBSTRING(convert(varchar, getdate(), 113),0,12),' ','/')+
        SUBSTRING(RIGHT(CONVERT(VARCHAR(26), GETDATE(), 109),14),0,6) AS TEST1

SELECT REPLACE(SUBSTRING(convert(varchar, getdate(), 113),0,12),' ','/')+
        RIGHT(CONVERT(VARCHAR(26), GETDATE(), 109),14) AS TEST2









- 只需用上面的查询替换getdate





--Just replace getdate in above query with

ReceivedMessages.ReceivedDateTime



--TEST1将在没有AM / PM的情况下输出TEST2将AM / PM附加到日期


--TEST1 will give output without AM/PM whereas TEST2 will append AM/PM to the date


这篇关于转换datetime sql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆