error handling when formatting dates