Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.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
C# SqlDataSource中的日期时间转换_C#_Asp.net_Sql Server_Utc - Fatal编程技术网

C# SqlDataSource中的日期时间转换

C# SqlDataSource中的日期时间转换,c#,asp.net,sql-server,utc,C#,Asp.net,Sql Server,Utc,我目前正在编写一份报告,其中使用太平洋标准时间(PST)作为日期的基础 我注意到,有时在检索特定日期的数据时,会缺少列 我发现数据库时间/服务器时间使用UTC,而报表使用PST/Localtime 在代码的“代码隐藏”部分中,如果未选择任何选项,则这是他们使用的默认日期 if (!Page.IsPostBack) { FromTB.Text = DateTime.Today.ToLocalTime().ToString("dddd, MMMM dd, yyyy h

我目前正在编写一份报告,其中使用太平洋标准时间(PST)作为日期的基础

我注意到,有时在检索特定日期的数据时,会缺少列

我发现数据库时间/服务器时间使用UTC,而报表使用PST/Localtime

在代码的“代码隐藏”部分中,如果未选择任何选项,则这是他们使用的默认日期

    if (!Page.IsPostBack)
    {
        FromTB.Text = DateTime.Today.ToLocalTime().ToString("dddd, MMMM dd, yyyy h:mm tt");
        ToTB.Text = DateTime.Today.ToLocalTime().AddMinutes(1439).ToString("dddd, MMMM dd, yyyy h:mm tt");
    }
下面是前面用于检索数据库中数据的代码

<asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString='<%$ ConnectionStrings:xxxxx %>' SelectCommand="select StudYear ,count(CAST(CreatedDate as DATE)) AS StudCount
from Student 
where CreatedDate >= @CreatedDate and CreatedDate <= @CreatedDate2 and StudYear is not null
group by StudYear
order by StudYear"

 <SelectParameters>
  <asp:ControlParameter ControlID="FromTB" Name="CreatedDate" PropertyName="Text" Type="DateTime" />
  <asp:ControlParameter ControlID="ToTB" Name="CreatedDate2" PropertyName="Text" Type="DateTime" />
 </SelectParameters>
</asp:SqlDataSource>

顺便说一句,如果您想要某一天的所有结果,可能最好使用如下内容:
date>=2020-03-09T00:00:00Z&&date<2020-03-10T00:00:00Z
(即大于或等于今天开始,小于明天开始)而不是你目前的方法,它不会包含任何超出
2020-03-09T23:59:00
。明白了。谢谢你的反馈,john。