none
SQL text for BETWEEN DATES? RRS feed

  • Question

  • I'm trying to write a sql date string with no luck. This is the part I need:

                    sqlstring += " Loaded_DateTime BETWEEN ";
                    sqlstring += "Date('" + StartdateTimePicker.Text + "')";
                    sqlstring += " AND Date('" + StopdateTimePicker.Text + "')";

    Just trying to see if Loaded_DateTime (which is stored as a smalldatetime) is between two DateTimePickers.Text (at this point I'm not even sure if  DateTimePicker.Text right).

    Can someone please give me the correct syntax?

    Thanks,

    Dennis
    Tuesday, December 18, 2007 3:17 AM

Answers

  • You need to pass dates as parameters (see KB article how to do this) and you do not need to put Date function into your SQL statement. It should look like (assuming you are using SQL Server), where @StartDate and @EndDate are parameters, which will accept values from application

     

                    sqlstring += " Loaded_DateTime BETWEEN @StartDate AND @EndDate";

     

     

    http://support.microsoft.com/kb/308049/en-us

    Wednesday, December 19, 2007 11:36 AM
    Moderator

All replies

  •  

    Hi Dennis,

     

    you can use dateTimePicker.Value property.

     

    Regards,

    VinilV

    Tuesday, December 18, 2007 6:12 AM
  • You need to pass dates as parameters (see KB article how to do this) and you do not need to put Date function into your SQL statement. It should look like (assuming you are using SQL Server), where @StartDate and @EndDate are parameters, which will accept values from application

     

                    sqlstring += " Loaded_DateTime BETWEEN @StartDate AND @EndDate";

     

     

    http://support.microsoft.com/kb/308049/en-us

    Wednesday, December 19, 2007 11:36 AM
    Moderator