开发者

get the hours for every month

开发者 https://www.devze.com 2023-01-08 02:10 出处:网络
I have created a function which will take two parameters as startdate, endda开发者_开发技巧te and returns hours from that. here i am getting both the total hours but i need to get individual month hou

I have created a function which will take two parameters as startdate, endda开发者_开发技巧te and returns hours from that. here i am getting both the total hours but i need to get individual month hours from that.

Regards, kumar


Use datediff

CREATE TABLE dbo.Duration
(
    startDate datetime2
    ,endDate datetime2
)
INSERT INTO dbo.Duration(startDate,endDate)
    VALUES('2007-05-06 12:10:09','2007-05-07 12:10:09')
SELECT DATEDIFF(HOUR,startDate,endDate) AS 'Duration'
FROM dbo.Duration;
-- Returns: 24


Use the sqlserver datediff function.

0

精彩评论

暂无评论...
验证码 换一张
取 消