如何获取仅作为日期的数据库datetime值

本文关键字:日期 数据库 datetime 何获取 获取 | 更新日期: 2023-09-27 18:12:32

hello我想在sql server中保存一个datetime数据类型的日期。在搜索屏幕上,我只给参数日期。

那么我如何设置为查询?我的代码是:

<asp:SqlDataSource 
     ID="SqlDataSource1" runat="server" 
     ConnectionString="<%$ ConnectionStrings:TAXIConnectionString %>" 
     SelectCommand="SELECT [TripId] FROM [BookingMaster] 
              WHERE ( ([PickupDateTime] = @PickupDateTime or @PickupDateTime is null))" 
     CancelSelectOnNullParameter="False">
     <SelectParameters>
         <asp:ControlParameter ControlID="txtBookingDate" 
              Name="PickupDateTime" PropertyName="Text" Type="String" 
              ConvertEmptyStringToNull="true" />
     </SelectParameters>
</asp:SqlDataSource>     

如何获取仅作为日期的数据库datetime值

如果使用Sql2008或更高版本,则可以使用DATE类型。你的选择命令看起来像。

SelectCommand="SELECT [TripId] FROM [BookingMaster] 
              WHERE ( (cast([PickupDateTime] as date) = @PickupDateTime or @PickupDateTime is null))"