Datetime Between query in SQLite RRS feed

  • Question

  • User1122132383 posted

    How can i write a datetime Between query on sqlite table column of type 'DateTime'

    I use the lines to insert values to table

       _mycmd.Parameters.AddWithValue("time",String.Format("{0:g}", DateTime.Now));

      _mycmd.Parameters.AddWithValue("date", DateTime.Now.ToShortDateString());  and it produce the entry

    5/29/2012 4:48 PM   and    5/29/2012 in the table.

    Now i want to use a select statement to get all rows where date between 2 values . How can i write that

    i try the query  where date BETWEEN @startime AND @endtime

    _mycmd.Parameters.AddWithValue("startime", dateFrom.Date.ToString());
    _mycmd.Parameters.AddWithValue("endtime", dateTo.Date.ToString());

    But this  way trates the search as string only not as date.

    Is any way to search as date

    Tuesday, May 29, 2012 7:22 AM

All replies

  • User418155246 posted
    _mycmd.Parameters.Add("@starttime", SqlDbType.DateTime);
    _mycmd.Parameters["@starttime"].Value = dateFrom.Date;
    _mycmd.Parameters.Add("@endtime", SqlDbType.DateTime);
    _mycmd.Parameters["@endtime"].Value = dateTo.Date;

    Tuesday, May 29, 2012 7:37 AM
  • User1122132383 posted
    no overload exists for Parameters with 2 arguments 
    Tuesday, May 29, 2012 7:42 AM
  • User418155246 posted

    _mycmd is of type SQLCommand right?

    Thursday, May 31, 2012 6:39 AM