Fix datetime handling