Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,
I have a log table, where I am storing the employee details whoever log in or log out,
I am copying my query below,
(btw the query is in MYsql)

SQL
SELECT  * FROM logdetails WHERE DATE_FORMAT(logdetails.CreatedLogDate,'%m/%d/%Y') >= '01/01/2013' AND DATE_FORMAT(logdetails.CreatedLogDate,'%m/%d/%Y') <= 01/03/2013

the above query is working fine if I am searching records which are between 1st January of 2013 to 3rd January of 2013.

But my real problem is if I am using the same query to search records between 1st Dec of 2012 to 3rd January of 2013, this query is failing to get records,

SQL
SELECT  * FROM logdetails WHERE DATE_FORMAT(logdetails.CreatedLogDate,'%m/%d/%Y') >= '12/01/2012' AND DATE_FORMAT(logdetails.CreatedLogDate,'%m/%d/%Y') <= 01/03/2013



can anyone tell me reason why this is happening.
Posted
Updated 2-Jan-13 18:45pm
v2

1 solution

Why do you need to format the date ? What form is it stored in ? Surely it's stored as a date ? You should work with date objects only, I suspect your code fails as it does string comparisons. If you must compare strings, use YYYY-MM-DD
 
Share this answer
 
Comments
salah9 3-Jan-13 6:40am    
thnx @Christian.....got it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900