Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,

Can anybody tell me why do i get this type of error i.e., "Implicit conversion from data type datetime to int is not allowed. Use the convert function to run this query." when i migrate to new database although all the columns and datatypes are same.

Thanks in advance
Posted
Comments
[no name] 11-Sep-14 7:34am    
Sure, you are trying to make a DateTime into an int and get the error.
Jagadisha_Ingenious 11-Sep-14 8:05am    
@Wes Aday: I am not making any conversion to the table but still i get this error. I have identity column in the table, if remove it by commenting the line of code it works fine.
[no name] 11-Sep-14 9:09am    
The error message is not lying to you. But we can't tell you anything about your code. We can't see your code, your database, your schema, your monitor or read your mind.
/\jmot 11-Sep-14 15:52pm    
if you really want to find the solution then will you please post your code here???

1 solution

The property of a DateTime object which correlates directly to an int (long) is the "Ticks" property so if you want to cast a date to a number use that.

The error of cause appears because you assign some date to an int, which is anyway wrong as ticks need more space and have to be a big int, called long (short for long int) so the int doesn't fit the number it could generate and therefore it wont work in essence unless you tell it how.

Interesting the following is possible although not recommended because it will give runtime errors eventually running regular dates :)

var x = (int) DateTime.UtcNow.Ticks;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900