Note that there are some explanatory texts on larger screens.

plurals
  1. POSearching 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
    text
    copied!<p>I have a GridView that should be populated according to a selected date, so I made the use of the <strong><code>Calendar control</code></strong>.</p> <p><strong>The problem</strong></p> <ul> <li><strong>Since the Calendar control's selected date is DateTime, unfortunately the selected date in the <code>Calendar</code> seems to be is in the format</strong>: <code>dd-MM-yyy</code> <br><em>example</em> 2013-02-15</li> <li><strong>while the <code>date field</code> in the Database is of type <code>datetime</code> meaning</strong>: <code>dd-MM-yyyy HH:mm:SS.ms</code> <br> <em>example</em> 2013-02-15 09:02:03.253</li> </ul> <p>So there will be no result since the Calendar control and the Database field are of different types.</p> <p><BR> <strong>What i tried</strong></p> <pre class="lang-asp prettyprint-override"><code>SqlDataSource1.SelectCommand = "Select * from table1 where start_date Like '% " &amp; calendar1.SelectedDate.Date &amp; " %' " </code></pre> <p>As you can see i worked the sqldatasource in code behind and i made the use of <code>Like</code> But even with the use of <code>Like</code> no results show <strong>due to Database having not only date but time too</strong>.</p> <p>I was also thinking to change the sql query itself, and precisely the field <code>start_date</code>, to omit the time (HH:mm:SS.ms) but is it possible to do so?</p> <p><BR></p> <h2>Edit:</h2> <p>Even if the Calendar Control's selected date and the field in the database are both DateTime, the search won't work because when searching with the Calendar Control its query will be Date and Time example <code>2013-01-01 00:00:00.000</code> while in the DB the time is not always 00:00:00 thus the need of Between as the answer below.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload