Problems with DateTime.Parse .... CultureInfo

Hi All,

I’m having trouble when getting a Date string from a website & trying to convert it to a DateTime, it’s in UK format as I get it & when I try to parse it using Datetime.ParseExact(ClaimDate,“dd/MM/yyyy",System.Globalization.CultureInfo.InvariantCulture)
It’s returning the month as the day, so when I run it against a datetime that has day > 12 it is failing. 17/11/2018 for example. I want the conversion to happen and keep it’s current format, which I’ve provided it above. I also tried Datetime.ParseExact(ClaimDate,“dd/MM/yyyy",nothing) but the same problem is happening. Could somebody please help?

image

@kieran_brophy

Try below expression.

   CDate(ClaimDate).ToString("dd/MM/yyyy")

@kieran_brophy - Looks like you also have time component attached to the date? is that right?

Try cdate as suggested by @lakshman , just to make sure cdate has some constraints as shown below…

If this does not work…please try as shown …

Hope this helps…

Dont use CDate, try Datetime.Parse instead. Also make clear in the beginning what is your local zone, like this. Do this Assign once in the beginning of your Process and never think about these kind of problems again:

System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(“de-DE”)

Hi

May I know which is month and date in your input 05/08/2018
And how you want the output to look like

@kieran_brophy

Thanks for your help, sorry I should have said - I’m storing the DateTime in a DataTable column. Will this solution work for that?

Hi, thanks for your help. I did what you said but it returned a DT row like this image

The input id dd/MM/yyyy & I’m converting the string to a datetime but somehow it’s switching htem over.

This is hte next date in the list, which may show more clearly what’s wrong.

image

Did you give it a try ??

Yes. I tried it but it is still flipping the month/day.

Something is wrong. If you apply correct datetime.parseexact it won’t flip.

Below screenshot shows that, it is reading fine…I think you client system or the local settings is MM/dd/yyyy, so when you do datetime.parseexact is giving MM/dd/yyyy and it is not flipping.

image

Please share the screenshot from the workflow and the sample data?