简体   繁体   English

转换 SQL Server 日期格式

[英]Convert SQL Server Date Format

I'm using this query:我正在使用这个查询:

select convert(nvarchar(MAX), getdate(), 100);

It's returning它回来了

Aug 16 2018  3:45PM

I'm trying to get this date format instead:我正在尝试获取此日期格式:

16 AUG 15:45

Please help me achieve it.请帮我实现它。 Thanks谢谢

试试这个:带格式功能

SELECT upper(FORMAT( getdate(), 'dd MMM HH:mm', 'en-US')) 

This gets you what you want, and without using the awfully slow FORMAT function:这让你得到你想要的东西,而且不使用非常慢的FORMAT函数:

SELECT D, CONVERT(varchar(6),DATEADD(HOUR, -1, D),13) + ' ' + CONVERT(varchar(5),CONVERT(time(0),DATEADD(HOUR, -1, D)),14)
FROM (VALUES(CONVERT(datetime2(0),'2018-08-16T15:45:00'))) V(d);

Edit: Seems the OP moved the goals posts again (initially they wanted the time changed from 01:38 AM to 13:38, and then 03:45 PM to 14:45), and as a result DATEADD isn't required.编辑:似乎 OP再次移动了目标帖子(最初他们希望将时间从上午 1:38 更改为 13:38,然后从下午 03:45 更改为 14:45),因此不需要DATEADD I haven't bothered removing this though, as it was correct at the time;不过,我并没有费心删除它,因为当时它是正确的; and I don't trust the goal posts won't move again.我不相信球门柱不会再次移动。

use upper and ' dd MMM HH:mm', 'en-US' format使用upper和 ' dd MMM HH:mm', 'en-US'格式

SELECT Upper( FORMAT( getdate(), 'dd MMM HH:mm', 'en-US' ))

it reutrns 16 AUG 11:03

Try this尝试这个

upper case 'Aug' to 'AUG'大写 'Aug' 到 'AUG'

SELECT UPPER( FORMAT( GETUTCDATE(), 'dd MMM HH:mm', 'en-US' ) )

Try this尝试这个

Query:询问:

select UPPER(FOrmat(GETDATE(),'dd MMM HH:mm'))

Result: 16 AUG 17:04结果:8 月 16 日 17:04

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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