get familiar with the fact that how the date stored internally, say, date in oracle, stores date and time, so when you compare 2 same dates, don't forget the time portion, if you really got a hard time, try to use string as a intermediate variable, and use convert functions to the proper database format, don't confuse yourself before you confuse the machine.