Rewrited cmp date function