Change Date Format(MDY)to(DMY)

Hai,
I have one column NTD/NTE data is 1/12/2024 (MDY) format i want 12/1/2024 (DMY). change whole column without foreach because i have so many rows . foreach affect performance.
Regards

@MD_Farhan1
Read range the Excel
In read range Enable Preserve Format

YourDataTable.AsEnumerable().ToList().ForEach(Sub(row) row(“YourDateColumn”) = DateTime.ParseExact(row(“YourDateColumn”).ToString, “M/d/yyyy”, System.Globalization.CultureInfo.InvariantCulture).ToString(“d/M/yyyy”))

Input:

image

Output:

image

Hi @MD_Farhan1

Can you try this query:

(From row In dt1.AsEnumerable()
                       Let originalDate = DateTime.ParseExact(row.Field(Of String)("YourOriginalDateColumn"), "M/d/yyyy", System.Globalization.CultureInfo.InvariantCulture)
                       Select transformedRow = dt1.Clone().Rows.Add(row.ItemArray.Concat({originalDate.ToString("dd/MM/yyyy")}).ToArray())
                      ).CopyToDataTable()

Make sure to change the datatable variable.

Regards


i got this error

Hi @MD_Farhan1

How about the following?

Input:

image

Output:

image

Cheers!!

Hi @MD_Farhan1

Try this since your date format is yyyy-MM-dd it throwed you an error.

(From row In dt1.AsEnumerable()
                       Let originalDate = DateTime.ParseExact(row.Field(Of String)("YourOriginalDateColumn"), "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture)
                       Select transformedRow = dt1.Clone().Rows.Add(row.ItemArray.Concat({originalDate.ToString("dd/MM/yyyy")}).ToArray())
                      ).CopyToDataTable()

Regards


i got Error

Hi @MD_Farhan1

Could you share sample input once.

Regards

@MD_Farhan1

PLease try my approach It works

What argument you give for invoke code

HI @MD_Farhan1

Bro could you please share the input excel with the specific dates as per your original date format in your excel.

Regards

@MD_Farhan1

Screenshot 2024-01-16 145702
I got Error

i want particular column. not all column

@MD_Farhan1

Try mention like below

Excel.Sheet("Sheet2").Range("A:A")

1 Like

@MD_Farhan1
Sequence9.zip (2.0 KB)

Please give the Format correctly give the exact format as it in Excel.Enable Preserve format in Read Range

Hi @MD_Farhan1

Use the below code in Invoke Code bro:

' Assuming dt is your DataTable and "NTD/NTE" is the column name
For Each row As DataRow In dt.Rows
    Dim originalDate As DateTime = DateTime.ParseExact(row("NTD/NTE").ToString(), "M/d/yyyy", System.Globalization.CultureInfo.InvariantCulture)
    row("NTD/NTE") = originalDate.ToString("dd/MM/yyyy")
Next

Invoked arguments:

Regards

1 Like

@MD_Farhan1

Considering the sample input as below:


Make sure to enable Preserve Format option in Read Range.

Code to be used in Invoke Code:

' Assuming dt is your DataTable and "NTD/NTE" is the column name
For Each row As DataRow In dt.Rows
    Dim originalDate As DateTime = DateTime.ParseExact(row("NTD/NTE").ToString(), "M/d/yyyy", System.Globalization.CultureInfo.InvariantCulture)
    row("NTD/NTE") = originalDate.ToString("dd/MM/yyyy")
Next

Invoked arguments:


Output:

Workflow:

Rergards

1 Like