Abstracted functionality to get datetime into separate JS function