c# - SQL Server 2005, storing only date and checking the condition with date only -


i using sql server, , wants store date part, if stores time no issue, while checking condition, want consider date. ex in .net.

select *    checkins   checkindate='" + datetime.now.toshortdatestring() + "'"; 

use convert function date portion of datetime column:

select *  checkins  convert(varchar(10),checkindate, 106) ='" +                                       datetime.now.toshortdatestring() + "'"; 

though, make date unambiguous not use toshortdatestring, custom format string:

datetime.now.tostring("d mmm yyyy") 

so together:

select *  checkins  convert(varchar(10),checkindate, 106) ='" +                                       datetime.now.tostring("d mmm yyyy") + "'"; 

Comments