Date Comparison Error

Hi Team,

I am comparing two dates

  1. Date1 (String) converted to Datetime format

  2. Date2 its in the form of DateTime default format (yyyy-mm-dd)

When i am trying to convert the Date2 to dd/mm/yyyy i am getting the below said err
String was not recognized as a valid DateTime

Hi

How are you trying to convert Date2 to the new format? Can you share the code?

HI @Robotics,

Can you please provide me the details.

From where you are reading the date(string) and which format?
Here are some examples please go through it

i hope those will help you…

DateTime is just a way of storing data, it doesn’t have a format until you output it somewhere. You can’t “convert” a DateTime to a different format. If it has the correct day, month, and year then you can freely compare it to Date1.

If you’re logging the Date2 or passing it somewhere you can do Date2.ToString(“dd/MM/yyyy”) to get it in the format that you need.

Looks like i’m a bit late on this but attached is what I think you need. Notice that capitasl m’s are required to get months (instead of minutes). Main.xaml (13.3 KB)

Hi @Robotics

Have a try of using this format

Datetime.ParseExact(StrDate,“dd/MM/yyyy”,system.Globalization.CultureInfo.InvariantCulture)
in Assign and try to compare

Thanks
Ashwin S

Hi @Robotics,

There is a certain thing you have to take into consideration while doing this. You have to convert both the date in the same format you can do that using CDate CDate will accept string and cast into the date or you can use what @AshwinS2.
Just go through the dates and select the suitable way to do this and which is going to be less error prone.

Best!!
Anmol

1 Like