question

chana avatar image
chana asked

Date Function

Hi I have 2 paramater as startdate and enddate After subtracting this ie @date = ( startdate- enddate) Now i want to conert it into @date=@date/60/60/24/365. It say me datetime cannot be converted into int. Kindly help me wiyth script
datetimedate-functions
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Oleg avatar image
Oleg answered
It appears that you are looking for a difference in seconds between 2 dates. If this is so then you don't really need to divide the difference by /60/60/24/365. The difference between 2 datetime values is still a datetime, you cannot divide it by an integer. To get what you need, use datediff function instead: declare @startdate datetime; declare @enddate datetime; declare @result int; -- populate your parameters (start@date - an hour ago, @enddate - now) select @enddate = getDate(), @startdate = dateadd(hour, -1, @enddate), @result = datediff(second, @startdate, @enddate); -- now select your result, it will be equal to 3600 :) select @result; You can read the [answer to this question][1], it has a pretty detailed explanation about datetime math. Oleg [1]: http://ask.sqlservercentral.com/questions/16420/php-with-mssql-strtotime-with-mssql-datetime-column
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.