in

System.Data.SQLite

An open source ADO.NET provider for the SQLite database engine

Comparison of dates in C# / SQLite

Last post 02-05-2011 2:40 AM by wijen. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 07-04-2010 6:09 AM

    Comparison of dates in C# / SQLite

    Hello, 

    I am attempting to usethe following code to count the number of bookings stored in my table since last Monday.  I have a datetime collumn (c_lastcalled) anda function that gives me the correct date of the previous Mondaybut I cannot get the query to return the correct count value.  In my test dataset I know there are 4 records that will match this query today but continue to get a count value of 0.  Here is the code:

                DateTime bookingsLimit = getLastMonday(DateTime.Today);
                /* Gets the date of the last monday from today (or today if it is Monday!) */
                sqlComm = new SQLiteCommand("SELECT COUNT(Calls.id) AS bookingsMade FROM Calls WHERE Calls.c_status = 2 AND DATE(c_lastcall) >= DATE(@lookfor)", sqlConn);
                SQLiteParameter paramDate = new SQLiteParameter("@lookfor");
                sqlComm.Parameters.Add(paramDate);
                paramDate.Value = bookingsLimit.ToShortDateString();
                sqlConn.Open();
                numBookings = Convert.ToInt32(sqlComm.ExecuteScalar());
                sqlConn.Close();
                sqlComm.Dispose();

    Can anyone assist me in seeing why this query fails or advise me of a better way to write these type of date based queries?  My locale (incase it matters) is en_gb (United Kingdom).

     Thanks Again,

     

    Mark Young

    tip2tail
    http://www.tip2tail.co.uk
    Application Development (C#.NET), Web Development (PHP, MySql, ASP.NET, jQuery), IT Support

    Hamilton, Scotland
  • 07-06-2010 5:07 AM In reply to

    Re: Comparison of dates in C# / SQLite

    Have you verified that your two invocations of date() are returning meaningful values? For instance, if you run the command-line 'sqlite3' program and invoke "select date('somevalue');", does it return what you expect?
  • 02-05-2011 2:40 AM In reply to

    • wijen
    • Top 500 Contributor
    • Joined on 02-03-2011
    • Posts 5

    Re: Comparison of dates in C# / SQLite

     we create a database in sqlite administrator with a table name homework and fieldname duedate having fieldtype date and deafult value current_date and fied constraints...but when we are inserting a value in a date column it prompts error.....

Page 1 of 1 (3 items)
Powered by Community Server (Commercial Edition), by Telligent Systems