Date comparison not working as expected