I have two date formats. One is if date format contains “AM” or “PM” then convert the date as “MM/dd/yyyy” and so on.
Else
Convert to format as “dd/MM/yyyy” and so on. But i am having error in this format that “String was not recognized as a valid DateTime”
Also the format is not correct. As i input the date as “1/5/2018” so it is considering the date as “M/d/yyyy” but it should be considered as “d/M/yyyy”
Please see my workflow attached.
Date Test.zip (14.0 KB)
You can use DateTime.TryParseExact
method to achieve this.
DateTime.TryParseExact(String, String[], IFormatProvider, DateTimeStyles, DateTime)
String array should hold all applicable date time formats.
Read more below.
thank you @KannanSuresh can you please do this in my attached workflow because i am getting error in IFormatProvider and DateTimeStyles using this format.
Try with this buddy @zeshanm9 and let know buddy
Date Test (2).zip (14.5 KB)
Cheers
@Palaniyappan Not working still i am getting error “Assign: String was not recognized as a valid DateTime” for this date format “13/05/2019 11:50:15”
Buddy i think there is no condition set for the input_time_split input of this LENGTH
in the if conditions buddy
Kindly add that condition of that much length in the if condition of length 19 without AM or PM and 21 or 22 for time having AM or PM and try buddy
Cheers @zeshanm9
@Palaniyappan Yes i did the change you suggested but still i am getting the same error
at which activity it is showing error buddy and what was the error buddy @zeshanm9
what was the value in that assign activity buddy
Cheers @zeshanm9
[13/05/2019] this value in
Assign = Convert.ToDateTime(Datetime.ParseExact(input_time_split,“dd/MM/yyyy”, system.Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”))
Buddy just mention like this buddy @zeshanm9
as this would give us the output of type datetime only buddy no need to convert datetime to string and then again to string and try to follow this in all assign activities buddy
Assign = Datetime.ParseExat(input_time_split,“dd/MM/yyyy”,system.Globalization.CultureInfo.InvariantCulture)
did that work buddy @zeshanm9