I need to compare two dates with different formats and find out, if date1 is earlier than date2.
Date1 is from SAP in stringformat “dd.MM.yyyy” and date2 is from excel in generic value(datetime) “dd/MM/yyyy hh:mm:ss”.
First I got the error that the string “dd.MM.yyyy” doesn’t have the right format for datetime. I tried to add 00:00:01 to the string and then convert to datetime, but it still doesn’t recognize it as right format.
Does anybody know how to convert and compare both dates (in an if activity) in order to find out if date1 is earlier than date2?
Parsing we can do within an assign like this:
DateTime.ParseExact(strDate1,Formats,CultureInfo.InvariantCulture,DateTimeStyles.None)
DateTime.ParseExact(strDate2,Formats,CultureInfo.InvariantCulture,DateTimeStyles.None)
And will receive following
the yellow lines are the statement that can be used within the condition block of an if
Kindly note:
As we used the dateformats within a string array we have to define the last forth parameter as well from the method signature. But with this we can use the same call for both formats (sure different datestrings are to pass)
an alternate for a single format parse would be like DateTime.ParseExact(strDate1,"dd.MM.yyyy",CultureInfo.InvariantCulture)