Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 我只想从SQL Server表中的datatime类型字段中获取正确格式的年/月/日_Asp.net_Sql_Sql Server_Sql Server 2008 - Fatal编程技术网

Asp.net 我只想从SQL Server表中的datatime类型字段中获取正确格式的年/月/日

Asp.net 我只想从SQL Server表中的datatime类型字段中获取正确格式的年/月/日,asp.net,sql,sql-server,sql-server-2008,Asp.net,Sql,Sql Server,Sql Server 2008,我在SQL Server中有一个表,它有一个datetime类型的orderDate列 我在我的asp.net页面中使用using System.Globalization,并使用此代码获取太阳能格式的系统日期历史记录,如1391/01/29年/月/日: PersianCalendar pc=new PersianCalendar(); DateTime dt = DateTime.Now; string year= pc.GetYear(dt).ToString(); string

我在SQL Server中有一个表,它有一个datetime类型的orderDate列

我在我的asp.net页面中使用using System.Globalization,并使用此代码获取太阳能格式的系统日期历史记录,如1391/01/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中编写一个select查询,它工作正常,但当我获得此列值并在另一个asp.net页面中使用SqlDataSource的网格视图中显示它时,结果如下所示:

AM 12:00:00  9/1/1391 
但它应该显示这样的结果

1391/09/01
我不知道为什么会发生这种情况?

在绑定字段上设置属性:

<asp:BoundField DataField="<Your Date Field>" HeaderText="<Column Header>"
                DataFormatString="{0:yyyy-MM-dd}"  />
设置绑定字段的属性:

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

或者,您可以在传递到应用程序之前转换服务器上的日期值

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

或者,您可以在传递到应用程序之前转换服务器上的日期值

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

谢谢,现在它可以正常工作了。我还有一个问题,我使用了这个命令:从OrdersView中选择minid,[idfromIndex],其中[idfromIndex]插入从OrdersView中选择DISTINCT[idfromIndex],其中IsObserve='True'和Ispay='True'和orderDate>='1390/09/01'和orderDate很酷,很高兴它能工作。如果你不介意的话,有机会请接受我的回答。您应该将另一个问题作为新的独立问题发布。谢谢,现在它可以正常工作了。我还有一个问题我使用了此命令:从OrdersView中选择minid,[idfromIndex],其中[idfromIndex]插入从OrdersView中选择独立的[idfromIndex],其中IsObserve='True'和Ispay='True'和orderDate>='1390/09/01'和orderDate很酷,很高兴它起作用了。如果你不介意的话,有机会请接受我的回答。你应该把你的另一个问题作为一个新的独立问题发布。