Corrected date handling code in main function