Your LAST_MODIFIED_TIME is (presumably) a date-time, but you are comparing it with character values from your TO_CHAR functions. Leave all the dates as dates and it should work. Also, you can use "BETWEEN date1 AND date2" to catch dates inside a range.