Dear Community,
I have a input string, which I want to convert to datetime. Normally I could use Assign = Date.ParseExact(“17.03.2020”,“dd.MM.yyyy”,System.Globalization.CultureInfo.InvariantCulture). That works fine. The Challenge is, that in the end I need the format “dd.MM.yyyy”, but the input String can be in a different format. For example “5.3.2020” or “15.3.2020” or “1.10.20” and so on. This causes errors
Is there any solution for this? Any oppurtunity to recognize the format and to convert it?
Thank you very much!
it is always “day.Month.year”
If MyStr
is the string containing your input date, you can use:
Date.ParseExact(String.Concat(MyStr.Split(".")(0).ToString("D2"), "-", MyStr.Split(1).ToString("D2"), "-", MyStr.Split(2).ToString("D4")), "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture)
.
Srini84
(Srinivas Kadamati)
July 17, 2020, 11:45am
4
@Jonathan_Langer
Please check as below
Mark as solution if this helps
Thanks
Assign activity warns me, that Int can not be converted to char and open strict on cannot convert from string to char.
what did you right in the second assign activity? or what datatype is the TimeSplit
Srini84
(Srinivas Kadamati)
July 17, 2020, 11:53am
7
@Jonathan_Langer
Second Activity is to TimeSplit which is a String (Array of String) type
TimeSplit = currentTime.Split("."c)
Hope this helps
Thanks
1 Like
ppr
(Peter Preuss)
July 17, 2020, 12:02pm
8
have a look here on how to handle multiple formats with a single DateTime.ParseExact
@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…
system
(system)
Closed
July 20, 2020, 12:02pm
9
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.