I am scraping data from an Arabic website, the date format pulled is in this format “YYYY/MM/DD” which I am facing difficulties to change afterwards in Excel, as I have to manually do several steps to put it in the correct format that I need.
Can someone suggest how to handle this case please? Basically I want it to be in “DD/MM/YYY” format before writing it to the Excel file at the end of my process.
I just tried it and I am getting and error “Message: String was not recognized as a valid DateTime.” , I checked the data column type of my data table and it is a “String” format.
Do I have to change the data column type to “Date and Time” before implementing what you proposed plz?
Now Date.ParseExact is looking for a format yyyymm/dd but in your initial question you said the input strings are in yyyy/MM/dd format.
I am assuming here that you have the correct datetime string codes which match with your input string.
It would also be good to include a data sample of your input string cause date time parsing need to be quite precise since for example an MM is not equal to mm and thereby the parsing might fail.
You are doing some basic mistake.
If the Input is 2021-03-09 use, DateTime.ParseExact(row("Issue").ToString(),“yyyy-MM-dd”,Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”)
If the Input is 2021/03/09 use, DateTime.ParseExact(row("Issue").ToString(),“yyyy/MM/dd”,Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”)