Reputation: 259
To make the story short I have a table inside of which I have a column of type Date/Time. I used MS Acces 2013 to create the database. Now, I need at a certain point in my app to check and delete all the records that are having their date smaller than today. Let's say that conn
is my connection to my database. I wrote:
conn.Open();
string delRec = "DELETE FROM myTable WHERE myDateTimeColumn < '" + DateTime.Now + "'";
ExecQuery(delRec);
conn.Close();
If I replace the string with, let's say:
string delRec = "DELETE FROM myTable WHERE anIntColumn < 21";
everything is running just fine. What am I doing wrong? Many thanks.
Upvotes: 1
Views: 54
Reputation: 46
Have you tried DateTime.Now.Day method i.e.
conn.Open();
string delRec = "DELETE FROM myTable WHERE myDateTimeColumn < '" + DateTime.Now.Day + "'";
ExecQuery(delRec);
conn.Close();
Hope it will help you.
Upvotes: 0
Reputation: 110
ACCESS is not recognizing as a date passed in WHERE clause.
conn.Open();
string delRec = "DELETE FROM myTable WHERE myDateTimeColumn < '#" + DateTime.Now + "#'";
ExecQuery(delRec);
conn.Close();
There may be one more point to check that are you passing same date format in where clause parameter. e.g 'YYYY/MM/DD'
Can you try this one. Hope this will help
Upvotes: 0
Reputation: 1081
You could use the built in Now() function:
string delRec = "DELETE FROM myTable WHERE myDateTimeColumn < Now()";
Upvotes: 1