日期格式返回为 mm/dd/yyyy hh:mm:ss AM/PM [英] Date format returned as mm/dd/yyyy hh:mm:ss AM/PM

查看:30
本文介绍了日期格式返回为 mm/dd/yyyy hh:mm:ss AM/PM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 sql 的新手,我的公司只是把我的头投入到这个问题中并说去做.因此,非常感谢任何帮助.我正在尝试以 mm/dd/yyyy hh:mm:ss AM/PM 格式获取日期,例如 09/26/2014 11:04:54 AM 的日期.我试过使用代码:

I am brand new to sql my company just kinda threw me head long into this and said do it. So any help is greatly appreciated. I am trying to get a date to come out in the format of mm/dd/yyyy hh:mm:ss AM/PM so for example a date of 09/26/2014 11:04:54 AM. I have tried using the code:

Select Convert(nvarchar,EntryDate,101)
From DB1

然而,它只返回 2014 年 9 月 26 日.我也试过

However that returns just 09/26/2014. I also tried

Select Convert(nvarchar,EntryDate,100)
From DB1

但这会返回 2014 年 9 月 26 日上午 11:04

but this returns Sep 26 2014 11:04AM

不知道从这里去哪里.再一次感谢你的帮助.顺便说一句,我使用的是 SQL Server 2012.

Not sure where to go from here. Again thanks for the help. BTW I am using SQL Server 2012.

推荐答案

由于您使用的是 SQL 2012,格式函数应该可以工作:

Since you're on SQL 2012 the format function should work:

declare @date datetime = '2014-09-26 11:04:54'
select FORMAT(@date,'MM/dd/yyyy hh:mm:s tt')

结果:09/26/2014 11:04:54 AM

在你的情况下是:

Select FORMAT(EntryDate,'MM/dd/yyyy hh:mm:s tt')
From DB1

这篇关于日期格式返回为 mm/dd/yyyy hh:mm:ss AM/PM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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