refactor datetime string to function