tags:

views:

869

answers:

2

How can I use .NET DataSet.Select method to search records that match a DateTime? What format should I use to enter my dates in?

+2  A: 

The best method is dd MMM yyyy (ie 15 Sep 2008). This means there is no possiblity of getting it wrong for different Locals.

ds.select(DBDate = '15 Sep 2008')

You can use the DateFormat function to convert to long date format as well and this will work fine too.

Leo Moore
A: 

I use the following for the SQL Select:

    public string BuildSQL()
    {
        // Format: CAST('2000-05-08 12:35:29' AS datetime)
        StringBuilder sb = new StringBuilder("CAST('");

        sb.Append(_dateTime.ToString("yyyy-MM-dd HH:mm:ss"));
        sb.Append("' AS datetime)");

        return sb.ToString();
    }
creohornet