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

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

问题描述

我是全新的sql我的公司只是有点把我的头长在这里说,做到这一点。所以任何帮助非常感谢。我正在尝试以mm / dd / yyyy hh:mm:ss AM / PM的格式出现日期,例如日期为09/26/2014 11:04:54 AM。我尝试使用代码:

 选择转换(nvarchar,EntryDate,101)
从DB1

但是只返回09/26/2014。
我也尝试过

 选择转换(nvarchar,EntryDate,100)
从DB1

但这返回Sep 26 2014 11:04 AM



不确定从哪里去。再次感谢您的帮助。 BTW我正在使用SQL Server 2012。

解决方案

  DECLARE @Date_Value DATETIME = GETDATE() ; 


SELECT CONVERT(VARCHAR(10),@Date_Value,101)+''
+ LTRIM(RIGHT(CONVERT(CHAR(20),@Date_Value,22) 11))


结果:09/26/2014 5:25:53 PM



您的查询



  SELECT CONVERT(VARCHAR(10),EntryDate,101)+''
+ LTRIM(RIGHT(CONVERT(CHAR(20),EntryDate,22),11))
从DB1


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

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

Select Convert(nvarchar,EntryDate,100)
From DB1

but this returns Sep 26 2014 11:04AM

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

解决方案

DECLARE @Date_Value DATETIME = GETDATE();


SELECT CONVERT(VARCHAR(10), @Date_Value, 101) + ' ' 
       + LTRIM(RIGHT(CONVERT(CHAR(20), @Date_Value, 22), 11))


RESULT: 09/26/2014 5:25:53 PM

Your Query

SELECT CONVERT(VARCHAR(10), EntryDate, 101) + ' ' 
       + LTRIM(RIGHT(CONVERT(CHAR(20), EntryDate, 22), 11))
From DB1

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

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