Incorrect call to date() after formatting date to string