使用以下查询:
SELECT REPLACE(CONVERT(VARCHAR(11), GETDATE(), 106), ' ', '/') + ' '
+ CONVERT(VARCHAR(8), GETDATE(), 108) as [DD/Mon/YYYY HH:MM:SS]
在您的查询中:
SELECT [ID]
,REPLACE(CONVERT(VARCHAR(11),ReceivedMessages.ReceivedDateTime , 106), ' ', '/') + ' '
+ CONVERT(VARCHAR(8), ReceivedMessages.ReceivedDateTime , 108) as RecievingDate
FROM [CmsSMSDb].[dbo].[ReceivedMessages]
where Convert(date,ReceivedDateTime)>= @DateFrom
AND Convert(date,ReceivedDateTime)<= @DateTo
[编辑] 对于 12 小时格式,写为:
SELECT REPLACE(CONVERT(VARCHAR(11), GETDATE(), 106), ' ', '/') + ' '
+ substring(CONVERT(VARCHAR, GETDATE(), 109),13,
Len (CONVERT(VARCHAR, GETDATE(), 109))) as [DD/Mon/YYYY HH:MI:SS:MMMAM (or PM)]
并将您的查询修改为:
SELECT [ID]
,REPLACE(CONVERT(VARCHAR(11),ReceivedMessages.ReceivedDateTime , 106), ' ', '/')
+ ' '
+ substring(CONVERT(VARCHAR, ReceivedMessages.ReceivedDateTime , 109),13,
Len (CONVERT(VARCHAR, ReceivedMessages.ReceivedDateTime , 109))) as RecievingDate
FROM [CmsSMSDb].[dbo].[ReceivedMessages]
where Convert(date,ReceivedDateTime)>= @DateFrom
AND Convert(date,ReceivedDateTime)<= @DateTo