Nelson.R
(Randell Persad)
April 13, 2022, 10:58pm
1
Reading an excel file and storing the date as a date time variable however I am getting an error for this date “7/2/2022” in the excel file. The format is dd/MM/yyyy.
When the robot reads in the cell it prints it as, “07/02/2022” 00:00:00.
Code Here:
Datetime.ParseExact(rDetail(“Date”).ToString,“dd/MM/yyyy”,System.Globalization.CultureInfo.InvariantCulture)
lakshman
(Ganta lakshman)
April 14, 2022, 12:41am
2
@Nelson.R
Try below expression.
Datetime.ParseExact(rDetail(“Date”).ToString,{"dd/MM/yyyy","d/M/yyyy"},System.Globalization.CultureInfo.InvariantCulture).ToString("dd/MM/yyyy")
The issue is that your string “07/02/2022 00:00:00" is not recognized. You can replace “00:00:00” by empty string and try again.
Try the expression below.
Datetime.ParseExact(rDetail(“Date”).ToString.Replace(“00:00:00”,“”).trim,“dd/MM/yyyy”,System.Globalization.CultureInfo.InvariantCulture)
Nelson.R:
Hi @Nelson.R ,
If the formats are all dd/MM/yyyy
and maybe some have the time formats as well.
Then maybe we can only consider the first half of the Date value by Split.
We can Check if the Below Works :
Datetime.ParseExact(Split(rDetail("Date").ToString.Trim)(0).Trim,"dd/MM/yyyy",System.Globalization.CultureInfo.InvariantCulture)
system
(system)
Closed
April 19, 2022, 1:20pm
5
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.