0

HI I am writing a sample application to insert and retrive datetime format . The Insert i did was sucessfull but dont know why it fails when i query to retrieve it . .

My insert goes like this..

string SqlQuery = "INSERT into BenchMarking Values (" + i + " , 'XXXX','This is a testing','M','2010-05-05 05:06:01')";
        sqlWrapper.ExecuteNonQuery(SqlQuery);

but when i query them its not returning me anything ...

retrive query

   string sqlQuery = "select Id from BenchMarking where Datetime = '2010-05-05'";
reader = sqlWrapper.ExecuteQuery(sqlQuery);

anyone knows why this is happening?

0

3 Answers 3

2

If you specify 2010-05-05 as a DATETIME value, it will default to 2010-05-05 00:00:00 which is different from the record you inserted.

What you are probably looking for is DATE() which extracts the date part from a DATETIME value.

select Id from BenchMarking where DATE(Datetime) = '2010-05-05'
Sign up to request clarification or add additional context in comments.

Comments

0

You probably need to change your query to select Id from BenchMarking where Date(Datetime_column_name) = '2010-05-05'

Comments

0

"select Id from BenchMarking where (CONVERT(VARCHAR(10), ArrivalTime, 111) = '2010/05/05')"

you need to format the date to varchar.. for formatting, u can use this..

http://www.sql-server-helper.com/tips/date-formats.aspx

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.