正确格式的必填日期 [英] Required Date in Correct Format
问题描述
亲爱的朋友,
早安!!
我有一个带有显示数据的Gridview.顺便说一下,我正在Asp.net C#,sqlserver 2005上工作.
在Gridview中,我的日期显示为5 \ 18 \ 2012 12:00:00 am
所以我的要求是显示5 \ 18 \ 2012不需要时间.
请告诉我,该如何解决.
注意:我需要的日期为MM \ DD \ YYYY 18 \ 05 \ 2012
请帮忙帮忙.
谢谢大家.
Dear Friends,
Good Morning !!
I have a Gridview with displayed data in it. by the way am working on Asp.net C#, sqlserver 2005.
In Gridview my date is displaying 5\18\2012 12:00:00 am
So My Requirement is to display 5\18\2012 No need of time.
Please tell me , how to solve this.
Note: I need date as MM\DD\YYYY 18\05\2012
Please help help help.
Thanks guys.
推荐答案
尝试以下示例:
在sql中:
选择(CONVERT(VARCHAR(10),YourField,103)+''''+ CONVERT(VARCHAR(15),YourField,108))作为DateTime
在c#:
字符串dt = Date.Now.ToString("dd-MM-yyyy");
Try this Example:
in sql:
select (CONVERT(VARCHAR(10), YourField, 103) + '' '' + CONVERT(VARCHAR(15), YourField, 108)) as DateTime
in c#:
string dt=Date.Now.ToString("dd-MM-yyyy");
嗨 用这个
hi use this
<asp:BoundField DataField="YourDateField" HeaderText="SomeHeader"
DataFormatString="{0:MM-dd-yyyy hh:mm tt}" />
如果您要绑定存储过程,则尝试仅更改存储过程中的日期
and if you are binding with stored procedure then try to change date in stored procedure only
您好,
您可以对gridview中的Date列使用以下代码:
Hello,
You can use following code for Date Column in gridview:
<asp:boundfield headertext="Some Header Text" datafield="SomeDateFromDatabase" dataformatstring="{0:MM/dd/yyyy}" xmlns:asp="#unknown"></asp:boundfield>
这篇关于正确格式的必填日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!