If condition for date

Hi All,

I am using below code in an invoke code to check if a date is of particular format then change it to a different format, but I am getting error.

Please help!

dt.AsEnumerable.ToList.ForEach(Sub(row)
If Date.TryParseExact(row("Date"),“MM/dd/yyyy hh:mm:ss”,Nothing,Globalization.DateTimeStyles.None,Nothing).ToString) Then
    row("Date")= DateTime.ParseExact(row("Date"),“MM/dd/yyyy”,CultureInfo.InvariantCulture).toString
End If
End Sub
)

below is the error

image

Please help!!

HI @Dhruvi_Arumugam

Try with this expression

dt.AsEnumerable.ToList.ForEach(Sub(row)
If DateTime.ParseExact(row("Date").Tostring,"MM/dd/yyyy hh:mm:ss",Nothing,System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None,Nothing).ToString) Then
    row("Date")= DateTime.ParseExact(row("Date").Tostring,"MM/dd/yyyy",System.Globalization.CultureInfo.InvariantCulture)
End If
End Sub
)

Regards
Gokul

Below error is coming

image

Hi @Dhruvi_Arumugam

What is the condition in the If activity? You need to provide the condition in the IF activity

dt.AsEnumerable.ToList.ForEach(Sub(row)
If DateTime.ParseExact(row("Date").Tostring,"MM/dd/yyyy hh:mm:ss",System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None).ToString) Then
    row("Date") = DateTime.ParseExact(row("Date").Tostring,"MM/dd/yyyy",System.Globalization.CultureInfo.InvariantCulture)
End If
End Sub
)

Regards
Gokul

Hi @Gokul001

Thanks for your answers, I myself solved the issue.

Thanks!