String was not recognized as aa valid datetime

Hi all,
i’ve a problem when i read a cell in excel file (date format 20/10/2021) and i want to write it in a web portal.
I pass the argument excelDT.asEnumerable.Last()(“date”).ToString
and type into Convert.ToDateTime(myVarString).ToString(“dd-MM-yyyy”)
Any solution?
Thanks in advance

Hi,

Can you try the following expression?

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

Regards,