create common function to handle date and time