Search code examples
sql-servert-sqlms-accessdatabase-migration

Dividing a date value in T-SQL


I am working on migrating an Access program into SQL Server. The following is my SQL code taken directly from access.

(([Promise Date])-([Date Recieved]))/100

As you can see, I am attempting to do a division on a datetime value.

This is the error message i receive:

Msg 257, Level 16, State 3, Line 1
Implicit conversion from data type datetime to int is not allowed. Use the 
CONVERT function to run this query.

Both fields are type Datetime. Any ideas what I am missing?


Solution

  • I think if I am right you are looking for something like this

    SELECT DATEDIFF(day, [Promise Date], [Date Recieved])/100;
    

    If right you can get more details here