我想只有年/月/日以正确的格式从我DATATIME类型字段在我的表在SQL Server

问题描述:

我在SQL Server表它有一个orderDatedatetime我想只有年/月/日以正确的格式从我DATATIME类型字段在我的表在SQL Server

enter image description here

我用我的asp.net页面使用System.Globalization,并使用此代码,让我这样的1391年1月29日年/月/日的太阳能格式的系统日期史:

PersianCalendar pc=new PersianCalendar(); 
DateTime dt = DateTime.Now; 
string year= pc.GetYear(dt).ToString(); 
string month= pc.GetMonth(dt).ToString(); 
string day= pc.GetDayOfMonth(dt).ToString(); 

并能正常工作,然后我把日期存入我的表,然后写在SQL Server中的选择查询它工作正常,但是当我得到这个列的值,并显示在这另一个asp.net页面使用SqlDataSource我的网格视图它显示的结果是这样的:

AM 12:00:00 9/1/1391 

但它应该显示出如下结果:

1391/09/01 

我不知道为什么会发生这种情况?

设置的绑定字段的DataFormatString属性:

<asp:BoundField DataField="<Your Date Field>" HeaderText="<Column Header>" 
       DataFormatString="{0:yyyy-MM-dd}" /> 
+0

现在谢谢它的工作原理fine.I还有一个问题我用这个命令:SELECT分钟(ID),[idfromIndex] FROM OrdersView WHERE [idfromIndex] IN(SELECT DISTINCT [idfromIndex] FROM OrdersView其中IsObserve =” True'和Ispay ='True'and orderDate> ='1390/09/01'and orderDate 2013-02-10 19:23:14

+0

酷,很高兴它的工作原理。如果你不介意的话,请在你有机会时接受我的回答。您应该将您的其他问题作为一个新的独特问题发布。 – 2013-02-10 19:50:44

或者你可以传递给应用程序之前对服务器转换日期值。

SELECT replace(convert(varchar(10),getdate(),120),'-','/') date