• Register
0 votes

Problem :

I am getting bellow error related to datetime
the conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.
6 5 3
6,930 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

  • I think both the DATETIME and DATETIME2 map to System.DateTime in .NET So you cannot really do a "conversion", as it is really the same .NET type.
  • Also please note that there are two different values for the "SqlDbType" for these two.
  • On SQL Server the date range supported is quite different.
  • DATETIME supports 1753/1/1 to 9999/12/31, while DATETIME2 supports 0001/1/1 through eternity.
  • So what you really need to do is check for the year of the date and if it is before 1753, you need to change it to after 1753 in order for the DATETIME column in SQL Server to handle it.
9 7 4
38,600 points

Related questions

0 votes
1 answer 46 views
Problem : I was getting the following error when running a SQL the conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
asked Nov 12, 2019 peterlaw 6.9k points
0 votes
1 answer 82 views
Problem : I have one entity type called product which is generated by the entity framework. I have tried to write below query public IMyQueryable<Product> GetProducts(int myCategoryID) {     return from prod in db.Products     where prod.CategoryID== myCategoryID     select ... one select new Product { Name = p.Name}; it miraculously works correctly. How can I perform the custom select section?
asked Jan 27, 2020 jwilliam 3.9k points
0 votes
2 answers 289 views
Problem : Currently I am migrating from the Identity 1.0.0 to Identity 2.0.1. But the migrations code generated is nothing about the new IdentityUser. And It does not even add the new columns. So I tried to make the new project and also I ... current context At below line IdentityResult result = await UserManager.CreateAsync(user, model.Password); Any clue about the solution on my above problem?
asked Dec 25, 2019 alecxe 7.5k points
0 votes
1 answer 28 views
Problem: Currently I have the table called Student in the database with some of the values and I am trying to display the values in the webgrid with the help of entityframework. I have done exactly the same kind of work before many times using the Ado.net, but ... I assign the VAR value to List also is this my correct approach? Kindly guide me in fixing my problem related to Entity Framework.
asked Jul 3, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 6 views
Problem: I want to get month and year from date in SQL SERVER. I do not know how to do that. If someone could help me, it would be appreciated. Thanks
asked Oct 19, 2020 Code Learner 5.2k points
0 votes
1 answer 449 views
Problem : I have the table storing starttime and endtime. I am facing below error: &ldquo;Conversion failed when converting character string to smalldatetime data type.&rdquo; While selecting the below query using that table. select CAST(substring(CONVERT(varchar,convert(smalldatetime,o. ... face any error. But, when I select it from a table I got the error. Can somebody help me with this?
asked Jan 20, 2020 jwilliam 3.9k points
0 votes
1 answer 13 views
How can i apply any entity framework approach like code first and database first in the ASP.NET MVC application.
asked Sep 16, 2020 Daniel Anderson 4k points
0 votes
1 answer 74 views
Problem : My Query is giving the strange error as follows there is already an open datareader associated with this command which must be closed first.
asked Nov 15, 2019 peterlaw 6.9k points
0 votes
1 answer 1.4K views
Problem : I am currently working on a django and I have gotten the below error: &ldquo;Type object 'datetime.datetime' has no attribute 'datetime'&rdquo; On a below line: date = datetime.datetime(int(year), int(month), 1) Does someone know any reason for above error?
asked Jan 28, 2020 jwilliam 3.9k points