datetime function wasn't working with Internet Explorer.
Made some changes and added a polyfill for toISOString compatibility with older browsers.