Filtering by dates SQLite C #

0

I have a table in SQLite with several fields including a Text type date with the following format:

"2018-11-04 12:13:00"

Since SQLite does not have the Date field in problems to make queries of dates greater or lesser than one that happens with the same format since he takes it as a string, someone could tell me if it is possible to make this type of query ?

    
asked by DVertel 04.11.2018 в 18:13
source

1 answer

1

You could format the date using something like this

var FechaInicio = fecha.ToString("yyyy-MM-dd");
var FechaFin = fecha.ToString("yyyy-MM-dd");

using(var connection = new SQLiteConnection(cntnStr))
{
    connection.Open();

    string query = "select * from tabla where campoDate >= @FechaInicio and campoDate <= @FechaFin";
    SQLiteCommand cmd = new SQLiteCommand(query, connection);
    cmd.Parameters.Add(new SQLiteParameter("@FechaInicio", FechaInicio));
    cmd.Parameters.Add(new SQLiteParameter("@FechaFin", FechaFin));

    var reader = cmd.ExecuteReader();

    //resto codigo
}

if the format needs the time you could use

var FechaInicio = fecha.ToString("yyyy-MM-dd HH:mm:ss");
    
answered by 05.11.2018 в 03:20