Change Column Type to Date through Assign

Hello all,

I have been reading many articles on how to change the column type of a data table from String to Date, but none of them has worked for except the For Each Row and changing each one on its own.

But I want a faster way through the Assign activity to change the whole date column to date in one activity.

I have two columns, one for Name, and the other for Date:

Name 20191128
Name 20191128
Name 20191128
Name 20191128
Name 20191128
Name 20191128

I want to convert the second column to be in this formate dd/MM/yyyy.

Thanks for your support.

@Salem_Ababneh

Do one thing. Create one template excel file with pre defined column format and then write data into it. I hope it will help you.

1 Like

@lakshman

Amazing workaround!

Is there any way to do it directly to the sheet through an Assign Activity?

1 Like

@Salem_Ababneh

Actually the issue with Excel file here not with your code. Based on Column format it will convert text irrespective of what we are writing .

Other alternative is to open the excel file and change the column format once writing data completed.

I hope above suggested method would be better and we are doing the same and it’s perfect.

1 Like

Yes we can of course
With assign activity like this in side the FOR EACH ROW loop with datatable as input obtained from Read Range activity
Like this by concatenating single quotes
row(“Date”) = “‘“ + DateTime.ParseExact(“yyyyMMdd”,”yyyyMMdd”,System.Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”)

But while using this data back using any for each row loop we need to replace the single quotes
Like this
Str_output = row(“yourcolumnname”).ToString.Replace(“‘“,””)

Cheers @Salem_Ababneh

1 Like

Thanks guys, I’ve created a new template Excel and all is okay now.

Many thanks again.

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