Change datetime to date and reorder some functions.