Formatting different types of dates

Hi,

I am scraping invoices and need to format the dates. Dates could be in any format such as below

28/10/20
28-10-20
2020-10-28
28.10.2021

etc…

I have tried the below assign code and many others just cant seem to find something that will work 100%

Assign: String was not recognized as a valid DateTime.

strparsedate = DateTime.ParseExact(dataSetResults.Tables(0).Rows(0).Item("InvoiceDate".ToString).ToString, “dd/MM/yyyy”,System.Globalization.DateTimeFormatInfo.InvariantInfo)

Hi

Did this thread help you resolve this

Cheers @benmyers

do you have an xaml of this. I keep getting errors

@benmyers

May I know in what format you want to change the date ?

yyyyMMdd

@benmyers

Try this.

              CDate("yourDateTimeVar").ToString("yyyyMMdd")

I had tried that but I didnt have the date set as date format in the taxonomy.

Its now working.

Thanks,

Have a look here:

DateTime.ParseExact(strDate1,Formats,CultureInfo.InvariantCulture,DateTimeStyles.None)

here we do handle different dateformats in one ParseExact

I have tied this. Still getting the same error.

strparsedate = DateTime.ParseExact(dataSetResults.Tables(0).Rows(0).Item("InvoiceDate".ToString).ToString,dateformat,CultureInfo.InvariantCulture,DateTimeStyles.None)

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