TyraS
(Tyra)
October 5, 2021, 4:08pm
1
I have a string. “29/05/2019”
Converted it to date using Datetime.parseexact(“29/05/2019”,“dd/MM/yyyy”,system.globalization.cultureinfo.invariantculture)
However, it differs on different computer system. if on a system with the datetime format of MM/dd/yyyy, the date becomes 05/29/2019 instead. How do i ensure that the conversion from string to date should always end up in dd/MM/yyyy regardless of the system date format?
ppr
(Peter Preuss)
October 5, 2021, 4:22pm
3
we can use within parseexact an array with dateFormat strings. So we can parse in one run both formats.
@BalaM1510
the main building block is an array with formats:
[grafik]
which can be used
DateTime.ParseExact(YourDateString, arrFormats, YourCultureInfo, DateTimeStyles.None)
from your question it can be derived:
a column with date strings is the input for a dateTime.ParseExact
the conversion result will update the value within the column
LINQ could be used for this. But as we have to be prepared for conversion fails LINQ is less helfull for this due:
ALL or Nothing is converted
intran…
But in case of both formats are not reliable detectable we will get an issue.
29/07/2021 and 05/17/2020 can be parsed and format is clear detectable
05/11/2021 is not clear detectable, as it can be May or November
One strategy could be (if its machine bound)
check all dates in advance and check which format is to apply
process it with calculated format string
TyraS
(Tyra)
October 6, 2021, 1:22am
4
hello, but this gave a string result at the end.
Hello @TyraS
What output did you get?
Can you share the screenshot…!!
Happy Automation
Best Regards
Er Pratik Wavhal
Srini84
(Srinivas Kadamati)
October 6, 2021, 3:27am
6
@TyraS
Check below for your reference
Reference
Hope this may help you
Thanks