Assign: The datetime represented by the string '31/12/2023 11:50:00' is not supported in the calendar System.Globalization.Gregorian.Calendar

Hello Community

I have a excel file with 2 columns, ID and test_datetime. The format for the test_datetime column is Custom dd/mm/yyyy hh:mm:ss and I cannot change this. I did a read range activity into a datatable. For each row in data table i assigned:

row(“test_datetime”) into DateTime.ParseExact(row(“test_datetime”).ToString, “dd/mm/yyyy hh:MM:ss”, System.Globalization.CultureInfo.InvariantCulture) but it gives me the error as mentioned in title.

I need to insert this DateTime value into Microsoft Access database, so I do need to keep the formatting of dd/mm/yyyy hh:MM:ss. How do I do this?

Thanks.

hi @Chen0000

Try this:

row("test_datetime") = DateTime.ParseExact(row("test_datetime").ToString, "dd/mm/yyyy hh:mm:ss", System.Globalization.CultureInfo.InvariantCulture).ToString("dd/mm/yyyy hh:mm:ss")

Regards

HI,

Can you try the following expression, because MM means 2 digit month, mm means 2 digits minute and HH means 24hour style hour.

DateTime.ParseExact(row("test_datetime").ToString, "dd/MM/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture)

Regards,

Hi,

Thanks for the reply! Now a different error comes out:
Assign: String " was not recognised as a valid DateTime.

This seems weird… i don’t know which String it is referring to

It seems input string is empty. Can you check your input data?
Or filter it in advance etc to avoid the exception.

Regards,

Thanks!! For some reason my datatable had an empty row… i solved it by filtering it out.

1 Like

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