This makes ReadRange already read it as a DateTime (unless PreserveFormat is checked).
All of the above solutions are essentially doing:
Get cell value (which is a DateTime) as a string
Parse it to DateTime (with fixed format, aside of Arivu’s answer)
Get elements out
There are unneeded steps there, which are actually dangerous - tostring will output in invariant culture which is month first. It worked here because day was low enough to also function as a month.
Only @arivu96 answer will not break your data, but it still has one line too much (the one quoted). Convert checks the type and if it is the target type it will straight up return it, otherwise will delegate to parse.
If you pass your cell directly to convert call effect will be the same, but without the danger of DateTime → String → DateTime roundtrip parsing.
Do note that all of these will fail if the cell is empty.
Hi Dear,
DateTime.ParseExact(S_date,“dd/MM/yy”, System.Globalization.CultureInfo.InvariantCulture) works always in “MM/dd/yyyy” format. Here you are getting wrong format with dd/MM then just behave as a string and split and then concate all three value(day, month and year) as per MM/dd/yyyy.