Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# DateTime.ParseExact

I have a tab delimited file which is being parsed and then inserted into a database. When I run into the date column, I have trouble parsing it.

The code I have is:

var insert = DateTime.ParseExact(line[i], "d/M/yyyy h:mm", CultureInfo.InvariantCulture); 

The string in line[i] is in the formats: 7/7/2011 10:48 , 10/20/2011 6:27

The exception I get says

The DateTime represented by the string is not supported in calendar System.Globalization.GregorianCalendar.

like image 920
Jonathan Avatar asked Dec 06 '11 14:12

Jonathan


1 Answers

Your format string is wrong. Change it to

insert = DateTime.ParseExact(line[i], "M/d/yyyy hh:mm", CultureInfo.InvariantCulture); 
like image 77
Fischermaen Avatar answered Sep 30 '22 13:09

Fischermaen