Refactor db_helper_compare_days()

Proposed fix for https://www.mantisbt.org/bugs/view.php?id=17980

I have not fully tested this.
Outside the scope of this change, but you're right.