updated formatDate function