0

I have this code written so far and it works for what I am doing but if I search for June 13 it will only look up until June 12, can someone help me figure whats wrong in my code? or where I can add a day interval? I tried and its just not working for me.

var db = Database.Open("RMS") ;
var selectCommand = "SELECT * FROM RMS";
var formSSO = "";
var fromDate= "";
var toDate= "";

    formSSO = Request.QueryString["formSSO"];
    fromDate = Request.QueryString["fromDate"];
    toDate = Request.QueryString["toDate"];


selectCommand = "(SELECT * from RMS WHERE SSO LIKE @0)";


if(!Request.QueryString["fromDate"].IsEmpty() ) {
    selectCommand = "SELECT * FROM RMS WHERE SSO LIKE @0 AND Created BETWEEN @1 AND @2";
}

if(Request.QueryString["formSSO"].IsEmpty() ) {
    <div class="simple"><strong>*SSO ID is Required.</strong></div>

}
var data = db.Query(selectCommand, formSSO, fromDate, toDate);
var columns = new[]{"ID", "SSO", "Category", "System", "Subject", "Created"};
var grid = new WebGrid(data, ajaxUpdateContainerId: "grid", defaultSort: "ID", columnNames: columns);
if (Request.QueryString[grid.SortDirectionFieldName].IsEmpty()) {
grid.SortDirection = SortDirection.Descending;
}
}
Alexandra
  • 65
  • 1
  • 2
  • 13

1 Answers1

0

One thing you can try is using <= and >= instead of BETWEEN like this:

selectCommand = "SELECT * FROM RMS WHERE SSO LIKE @0 AND Created >= @1 AND Created <= @2";

I hope that does the trick!

If not you can also brute force the to date to be one day further into the future and then use the BETWEEN operator just you are now like this:

            DateTime to_date = Convert.ToDateTime(to_date_string);
            to_date = to_date.AddDays(1);
            to_date_string = to_date.ToString();
Thomas Fonseca
  • 542
  • 4
  • 12
  • Sorry Alexandra try using parse exact the way the answer to this thread shows: http://stackoverflow.com/questions/14756176/convert-todatetime-in-c-sharp-from-specific-date-string – Thomas Fonseca Jun 14 '13 at 21:39