0

I have a program using a SQLite database which needs to remove a row after it's expiration date is lower than the current time. The table i am trying to interact with has a field with the id,name,expiration date,entrance date,code of costumers, each customer has a different expiration date and this data is retrieved by using:

DateTime.Now.AddDays(numberofdaysstaying)

and the current time is retrieved by using:

DateTime.Now

My sql code is executed in a different class named sqlManager and the function i use to auto-delete is:

        public void Autodelete()
    {
        using (SQLiteConnection sqlConn = new SQLiteConnection("Data Source=projecto.sqlite;Version=3;"))
        {
            sqlConn.Open();
            //create command
            SQLiteCommand sqlCommand = new SQLiteCommand("DELETE FROM cliente WHERE expirationDate < @td", sqlConn);
            sqlCommand.Parameters.AddWithValue(Datetime.Now));

            sqlCommand.ExecuteNonQuery();
        }

And this does nothing really, there is no exception or anything like that... it just doesnt delete a thing. Any tips on how to make this work?

wannabeLearner
  • 199
  • 1
  • 2
  • 16

1 Answers1

1

I would convert to unix time using date(expirationDate, unixepoch) then compare it to the time now in unix time. This should be easier because unix time is an integer. It is the time in seconds since 1970-01-01. I have linked below another question that answers how to get unix time in C#.

How to get the unix timestamp in C#

Community
  • 1
  • 1
Marc T
  • 26
  • 3