moved date formatting to a function