Question related to date type

Hello,
i’ve an input excel file with random date format (ddMMyyyy OR dd/MM/yyy OR ddMMyy, etc.),

considering that I’ll have to make a comparison between dates, for example calculating if it is greater or not to another date, how can I convert it in the correct way not knowing before the format?

1 Like

Hi @andreus91 ,

As long as you are aware of what all types of formats you can encounter, you can perform the string → DateTime conversion without any issue.

For that, you have to declare an Array of Strings like so:

image

Then assign the formats like so:

image

{"MM/dd/yyyy hh:mm:ss","M/dd/yyyy", "dd/MM/yyyy"}

And then use this snippet of code to perform the conversion->

DateTime.ParseExact(CurrentRow(ColumnNameOrIndex).ToString,arr_Format,Nothing,Nothing)

You can simply convert most dates using either Convert.ToDateTime() or CDate, but this doesn’t work with all formats, and you could end up converting the date into the wrong format as well, which is why I didn’t explain this first.

its better to keep track of all possible formats.

I hope that solves your query?

Kind Regards,
Ashwin A.K

Hi

Here you go similar scenario with sample workflows

Cheers @andreus91

Hi @andreus91

Create an Variable With String[Array] Let say → ArrDate

New String(){"ddMMyyyy","dd/MM/yyy","ddMMyy")

Use assign activity

DateTime.ParseExact("ColumnNameOr Index",ArrDate,System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None).ToString("dd.MM.yyyy")

Regards
Gokul