Dear All,
I am trying to convert date with correct format and correct date and month but there is issue i am facing data retrive from excel but date not showing correct. in Day picking month value and month picking day value. below snap for your refrence.


Tahir AnsariRank #366 · 6.8K reputationPosted Sep 6, 2023, 4:14 PM EDT
using System; using System.Globalization; // Sample date format (adjust to match your Excel data format) string excelDateFormat = "dd/MM/yyyy"; // Example: "25/09/2023" // Sample date value from Excel string excelDateValue = "25/09/2023"; // Example: "25/09/2023" try { // Parse the Excel date value using the specified format DateTime parsedDate = DateTime.ParseExact(excelDateValue, excelDateFormat, CultureInfo.InvariantCulture); // Now, 'parsedDate' contains the correctly formatted date Console.WriteLine(parsedDate.ToString("yyyy-MM-dd")); // Output: "2023-09-25" } catch (FormatException ex) { // Handle the exception if the date format is incorrect Console.WriteLine("Error: " + ex.Message); }assume that the date format in the Excel file is "dd/MM/yyyy." You should adjust the excelDateFormat variable to match the actual date format in your Excel data.
Amit MohantyRank #112 · 20K reputationPosted Sep 7, 2023, 2:08 AM EDT
Make sure that the date cells in Excel are formatted correctly. Excel allows you to format cells as dates in various date formats. Right-click on the date cells, select "Format Cells," and choose the appropriate date format.