Transform datatable string column into data time format (DD-MM-YYYY)

I’ve already done it with my column in the data table as a string and as a data time

String:

image

DateTime:

image

ensure following:
grafik

give a try on following:

create a variable of datatype String( ) - String Array
Name: arrFormats
Defaultvalue: {"yyyy-MM-ss","MM/dd/yyyy HH:mm:ss"}

use following conversion

DateTime.ParseExact(yourDateString, arrFormats, CultureInfo.InvariantCulture, DateTimeStyles.None)

stayed in this format:

image

correct format that should be: 08/10/2021

Code

DateTime.ParseExact(CurrentRow.item(“dt_ult_movimento”).ToString(), teste, CultureInfo.InvariantCulture, DateTimeStyles.None)

not sure if I got you. When you check the datatable (also we gave a statement to check and filter out all invalid dates) you will get 1 or more formats. This has to be used for conversion from string into dateTime with the usage of parse exact

I need to do the following conversion, I have a column in my data table that comes with the data like this: yyyy-MM-dd (example: 2021-10-01) may have null value too, I need to convert to the following format dd/MM/yyyy regardless of the data type of the final column, it can even be a string, as this data table will turn into a CSV.

this you will check with

  • open immediate panel (close to local tab)
  • type in: yourDataTableVar.Rows(0)(YourColNameOrIndex)

or for all
yourDataTableVar.AsEnumerable.Where(Function (x) Not DateTime.TryParseExact(x(YourColNameOrIndex).toString.Trim, “dd-MM-yyyy”, CultureInfo.InvariantCulture,DateTimeStyles.None, Nothing)).toList

as some other screenshots did show other formats

datatype of the data column from the datatable will be string (same or addtional helper column)

and procedure is Convert String into a datetime and return the date with a different format as string

e.g. (multiple input formats)

DateTime.ParseExact(yourDateString, arrFormats, CultureInfo.InvariantCulture, DateTimeStyles.None).toString("dd/MM/yyyy")
DateTime.ParseExact(yourDateString, YourSingleInputFormatString, CultureInfo.InvariantCulture).toString("dd/MM/yyyy")

As we have shown you the main Building blocks along with anaylsis techniques we are sure that you will get it done

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