Problem Changing Date Format

Hi All,

I’m a beginner to developing bots in studio and I have a problem I was hoping someone could help with.

I’m using an assign activity in a ‘For Each Row’ loop to run through my datatable capture an existing date from a particular column and then assign this date to different column in the datatable. The problem is my output is in the date format MM/dd/yyyy and I require it to be dd/MM/yyyy.

After searching for solutions using DateTime.ParseExact seems to be the most popular method but I am encountering a compiler error. The error message states ‘Globalization’ is ambiguous, imported from the namespaces or types ‘System.Web, System’.

My datatable does not have column headers so I am referencing the data using row(). Please see my code below.

Assign
row(16) = DateTime.ParseExact(row(4),“MM/dd/yyyy”, Globalization.CultureInfo.InvariantCulture).Tostring(“dd/MM/yyyy”)

I have added System.Globalization to the imported namespaces in Studio but still have the error. Can anyone help suggest a solution please?

Thanks

Hi. That’s weird if System.Globalization still does not work, but you always can use
DateTime.ParseExact(row(4),“MM/dd/yyyy”, Nothing).Tostring(“dd/MM/yyyy”)

upd. check out this panel
image

Hi thanks for your response.

I tried your suggested code but this did not seem to work either, however I have noticed in my original code I was missing the ‘System’ before globalization.

I have now changed this to read DateTime.ParseExact(row(4),“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture).Tostring(“dd/MM/yyyy”)

The compiler error has now changed to Option Strict On disallows implicit conversations from ‘Object’ to ‘String’

@michael.criddle
Add to the statement toString for the datacolumn access:

DateTime.ParseExact(row(4).toString,“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture).Tostring(“dd/MM/yyyy”)

About ‘Globalization’ is ambiguous, imported from the namespaces or types ‘System.Web, System’.

can be fixed by:

  • adding System before: System.Globalization.CultureInfo.InvariantCulture
  • suggested: import the namespace System.Globalization and change to the shorter form: CultureInfo.InvariantCulture

Hi Peter,

Thanks for your reply.

I have updated as below and that has worked in terms of getting rid of the compiler error but for some reason my date is still being output in the format MM/dd/yyyy.

DateTime.ParseExact(row(4).toString,“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture).Tostring(“dd/MM/yyyy”)

Any ideas why this could be occurring? Feel like I’m missing something really obvious.

Is anyone else able to suggest any solutions?

Thank you.