How to convert date format from mm-dd-yy hh:mm to mm/dd/yy hh:mm

Hi,

While reading CSV all results I get are in mm-dd-yy hh:mm format.
I need to convert it to mm/dd/yy.

What is the most efficient approach for changing these formats?
Thanks in advance.

Hi @bp777

Try out the below syntax to change date time format

Out_String_Variable=DateTime.ParseExact(yourdatevariable.toString(), “mm-dd-yy hh:mm”, Globalization.CultureInfo.InvariantCulture).ToString(“MM/dd/yyyy”)

Hope it solves your issue

Thanks
Robin

 DateTime.ParseExact("12-17-2020 14:00", "MM-dd-yyyy HH:mm", System.Globalization.CultureInfo.InvariantCulture).toString("MM/dd/yy HH:mm")
 "12/17/20 14:00"

we used HH to get handled 14 for 2 PM
other wise it would fail:

for the Flow we would recommend a for each / for each row / for each row in datatable

Edit: as the title and the description are different for the target format, just adopt it to you final definition

@bp777

Check below for your reference

Reference

Hope this may help you

Thanks

This is the error I get when using your expression:
Parsing to new date format: String was not recognized as a valid DateTime.

The variable I’m trying to format is a string

this is a typical trigger, that the used string is not within the expected format.

You can start to trim the value from the csv data column by using the trim methhod from string

Another recommendation would be to have a look on the csv data or checking the data within the immediate panel using a LINQ statement

I didn’t post this, but the format I need to change is exactly like this:
Date time for format: 10-19-21 03:33 PM
Maybe the part with “PM” is problematic?

10-19-21 03:33 PM is not a MM-dd-yy hh:mm format

give a try on following:

Keep in mind, that the configured format string is not elastic for a parseExact method. So we do need to define excactly as we do get within the data

1 Like

Thank you Peter!

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