The question is about converting a date value to a string after reading it from Excel

I have used the Excel activity to read the value of a certain cell in the Excel, which is shown in the attached image. However, I want to convert it to a string type, but encounter an error when I use the Format() function. Is there any solution to this problem?

Hi @shenyu

Please try this expression instead:

Assuming that datetime is in the format dd/MM/yyyy

dateValue = DateTime.ParseExact(datetime.ToString,"dd/MM/yyyy", Globalization.CultureInfo.InvariantCulture).ToString("yyyy-MM-dd")

Hope this helps,
Best Regards.

Hi @shenyu

Give a try with

DateTime.ParseExact(dateValue,{"M/d/yyyy","dd/MM/yyyy","d/M/yyyy","MM/dd/yyyy","MM/dd/yyyy hh:mm:ss", "dd/MM/yyyy hh:mm:ss"},System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None).ToString("yyyy-MM-dd")

Rememer to change your dateValue to String value

Regards!


Do I need to import any other packages?

@shenyu

Please change the variable name datetime from variables panel…DateTime is a class in vb.net and it not advised to use it as a variable name…that name is conflicting with the class…so once you change error should go off

Hope this helps

cheers

@shenyu

You can try changing the variable’s data type or variable name to verify whether it works. Let us know about the same.

Best Regards.

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