String was not recognize valid date time

convert.Todatetime(str_ETADate).Date.AddDays(-(str_MapTransitTime)).ToString(“dd/MM/yyyy”)

I have written above syntex for str_ETADate - str_MapTransitTime = 18/12/2022-5days = 13/12/2022 is require output. Both values are converted into string.
but not getting.

Please help on this

Hi @satish.rathi59 ,

Could you Check with the below Expression :

DateTime.ParseExact(str_ETADate,"dd/MM/yyyy",System.Globalization.CultureInfo.InvariantCulture).AddDays(-Cint(str_MapTransitTime)).ToString("dd/MM/yyyy")

As @supermanPunch suggested, using DateTime.ParseExact would be the Go-To solution to convert strings to date, and then work with DateTime functions. CDate, Convert.ToDateTime, DateTime.Parse tend to fail with certain type of dates.

DateTime.ParseExact lets you write the exact format (in this case it would be “dd/MM/yyyy”, but also an array of possible formats :slight_smile:

Hope this helps!

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.