Fix datetime comparison in relative datetime functions.
Closes #2987,#3514
Merge pull request #1235 from ADmad/2.3-caketime

Fix datetime comparison in relative datetime functions.