Hi. Im trying to extract a datatable from csv that contains dates on EU/AU format “dd/MM/yyyy hh:mm:ss tt” and determine which is the latest record but met an error.
Tried to use below but met an error.
Input: “11/07/2022 7:24:51 PM” > (Changed Date row from excel)
Assigned to a string: DateTime.ParseExact(row("Changed Date“).ToString,“MM/dd/yyyy hh:mm:dd tt”, System.Globalization.CultureInfo.InvariantCulture).toString(“dd/MM/yyyy hh:mm:dd tt”)
Error: “Assign: String was not recognized as a valid DateTime.”,
Note: Below works when “hh:mm:ss tt” is not included but this is crucial on my part since i have to determine the latest record. Also, i don’t necessarily need to convert to MM/dd/yyyy as long as i can determine which is the latest record up to the second.
Well, you have a string, but that doesn’t necessarily make it any easier to compare than before… as in, it’s still just a string, which is what you started with–you’re just displaying it differently.
If you want to compare dates then I would do it using a System.DateTime variable.
For example, convert your input string to a DateTime variable e.g. newDateVariable = DateTime.ParseExact(yourInputString,"MM/dd/yyyy h:mm:ss tt", System.Globalization.CultureInfo.InvariantCulture).
Now you have a proper date variable that you can perform any number of date related tasks on e.g. newDateVariable > anotherDateVariable or newDateVariable.AddMonths(1) etc…