Fixing bug when comparing date