Error in converting to dd-mm-yyyy

Hi All

I am trying to convert an extracted date from an excel sheet and convert it to dd-mm-yyyy

I’ve been using this method in another project, but it doesn’t seem to work this time. Any suggestions? see below for workflow and error

@ChrisPals,

Can you Please tell us the extracted date format.

Thanks,
Mohanraj.S

This is how the date looks in excel. But if I use type into and add the value row.item(11).toString it writes: dd-mm-yyyy hh:mm:ss

1 Like

while assigning strDate
kindly mention like this
strDate = row(11).ToString.Substring(0,10)
then use that strDate in the Datetime Parse method like this
strDate = Datetime.ParseExact(strDate,“dd/MM/yyyy”, System.Globalization.CultureInfo.InvariantCulture).ToString(“dd-MM-yyyy”)

or once kindly check the value of strDate using a writeline activity before to this conversion and check what is the format of the date and mention the same format here in the highlighted area, it will work for sure
strDate = Datetime.ParseExact(strDate,“dd/MM/yyyy”, System.Globalization.CultureInfo.InvariantCulture).ToString(“dd-MM-yyyy”)

hope this would help you
Cheers @ChrisPals

You can also try to use DateTime.FromOADate which is good to convert date created by the Excel Interop.

I found this link that may help:

https://www.dotnetperls.com/fromoadate

Hi @Palaniyappan

I tried your method but i keep getting this error, any suggestions?

thank you

image

image

1 Like

can youplesae try

row.item(11).tostring(“dd-MM-yyyy”)

Fine kindly use one write line activity next to the assign activity of strdate and
in the write line mention the strdate as input and lets check what is the date format actually getting displayed in the output panel
i have a doubt with the format because this error occurs only when we try to mention the date as month as there only 12 months and if we mention any date like 28 as month it will show error as there is no such month

so kindly include a write line activity and mention the strdate as input and lets check what is the output date format so that based on the we can mention the date format here in the highlighed area
i hope it would be like MM/dd/yyyy hh:mm:ss or MM-dd-yyyy hh:mm:ss
i guess so
lets try and mention the date format here once found, then it will work for sure buddy
strDate = Datetime.ParseExact(strDate,“dd/MM/yyyy”, System.Globalization.CultureInfo.InvariantCulture).ToString(“dd-MM-yyyy”)

we need to mention the date format that we see in the output panel for the obtained strdate from the excel , kindly try that and let know for any queries or clarification
i hope it should work

Cheers @ChrisPals

Hi @Palaniyappan

You where right. The extracted format was MM/dd/yyyy and therefore I did not use the right format in the parseExact.

I checked and corrected it.
Thank you for the solution!

1 Like

Fantastic
Cheers @ChrisPals

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