c# - Searching Gridview by Date, but the Calendar control picker (that is DateTime) includes the date and also the time, example: 2013-01-01 00:00:00.000 -
i have gridview should populated according selected date, made use of calendar control.
the problem
- since calendar control's selected date datetime, unfortunately selected date in
calendarseems in format:dd-mm-yyy
example 2013-02-15 - while
date fieldin database of typedatetimemeaning:dd-mm-yyyy hh:mm:ss.ms
example 2013-02-15 09:02:03.253
so there no result since calendar control , database field of different types.
what tried
sqldatasource1.selectcommand = "select * table1 start_date '% " & calendar1.selecteddate.date & " %' " as can see worked sqldatasource in code behind , made use of like use of like no results show due database having not date time too.
i thinking change sql query itself, , precisely field start_date, omit time (hh:mm:ss.ms) possible so?
edit:
even if calendar control's selected date , field in database both datetime, search won't work because when searching calendar control query date , time example 2013-01-01 00:00:00.000 while in db time not 00:00:00 need of between answer below.
you can use date extract records database using datetime field. dont think using on dates idea. specify , date ranges 1 day worth of data:
sqldatasource1.selectcommand = "select * table1 start_date >" & calendar1.selecteddate.date & " , start_date < " & calendar1.selecteddate.date.adddays(1) or using between operator:
sqldatasource1.selectcommand = "select * table1 start_date between " & calendar1.selecteddate.date & " , " & calendar1.selecteddate.date.adddays(1)
Comments
Post a Comment