How to convert date format from dd-mm-yyyy to MM-dd-yyyy in excel

For example i have date in excel as 10-05-2023 from this to 05-10-2023

Hi @sathish_Kumar6

Give a try with the following

DateTime.ParseExact(strInput, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture).ToString("MM-dd-yyyy")

image

Remember to replace the strInput variable for your currentRow variable

Regards


Im getting error

hi @sathish_Kumar6 ,

Can you provide the date that you’re getting in the sts variable in assign activity, Did you give the correct format there?

Or can you screenshot the date that you’re getting from Excel file?

The expression to convert data is written below and that should work if your input date format is coming as dd-MM-yyyy
DateTime.ParseExact(sts, “dd-MM-yyyy”, System.Globalization.CultureInfo.InvariantCulture).ToString(“MM-dd-yyyy”)

Thanks,
Aditya

Hi @sathish_Kumar6

Try this

Regards,

Hi @sathish_Kumar6

Can I see the value you are retrieving in that variable please? I want to check the format

Regards

I have tried the given format but its not working so Iam Passing the variable as string so Is there any issue

Hi @sathish_Kumar6 : can you share your source file from where you’re reading the date column?

Sample.xlsx (10.0 KB)
Please check that sample file

@sathish_Kumar6

Use this Expression for changing Date Time Format.

DateTime.ParseExact(DateTime_Variable, “dd-mm-yyyy”, System.Globalization.CultureInfo.InvariantCulture).ToString(“MM-dd-yyyy”)

Regards

image
Try to use this one
datetime.Parse(CurrentRow(3).ToString).Tostring(“dd-MM-yy”)
or
DateTime.ParseExact(CurrentRow(3).ToString,“MM/dd/yyyy”,system.Globalization.CultureInfo.InvariantCulture).ToString(“dd-MM-yyyy”)
image

Hi @sathish_Kumar6 ,

for me the date is visible in this format from your sample file: i.e. dd/MM/yyyy
image

So the expression for this would be:
DateTime.ParseExact(DateTime_Variable, “dd/MM/yyyy”, System.Globalization.CultureInfo.InvariantCulture).ToString(“MM-dd-yyyy”)

Hi @sathish_Kumar6 ,

Could you check the below Post, it does address the same issue, you could just use the format that is required for your case :

You do this in Excel by editing the cell’s formatting. It’s important to understand that datetimes don’t have a format. You format them when you view/output them. That’s what Excel is doing. It’s storing a datetime value and displaying it in a certain format - which you can change by right-clicking the cell (or column, or row, etc)

1 Like

Hi @sathish_Kumar6

Just enable the preservet formar property in your read range activity, with this we will ensure that we are retrieving the same format we are watching in excel, then use the code i’ve shared

DateTime.ParseExact(strInput, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture).ToString("MM-dd-yyyy")

Regards!

1 Like

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