日期时间字段格式问题 [英] Datetime field format issue
本文介绍了日期时间字段格式问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
i am saving 'patientadmissiondate' field as DateTime.Now;. When i view table data i see the values in this column in this format '11/24/2015 10:46:05 AM'..
however when i do select * from tbpatientadmissiondate i see the values in this column as '2015-11-24 10:46:05.443'
Due to this i am having issue returning the records which match a particular 'patientadmissiondate' .Please guide!
推荐答案
试试吧,
Hi, Try this,
select CONVERT(VARCHAR(50),GETDATE(),22)
它会将结果视为
It will gie the result as
11/24/15 12:39:11 PM
请参阅我们可以根据您的要求使用的格式链接。
http://www.sql-server-helper.com/sql-server-2012/format-function-vs-convert- function.aspx [ ^ ]
http://www.sqlusa.com/bestpractices/datetimeconversi on / [ ^ ]
Hi ,
By Default Sql server saving datetime in yyyy-mm-dd hh:mm:ss formate.
if you have issue in date formate while retrieving you can change date formate and compare with patientadmissiondate.
例如
e.g.
select CONVERT(varchar(10), CONVERT(datetime, GETDATE(), 101), 101)
C#侧
: -
in C# Side :-
Please try Below code
var rep = from s in ctx.tbreports
where s.dateofreport.ToString("yyyy-MM-dd") == date.ToString("yyyy-MM-dd")
select s;
这篇关于日期时间字段格式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文