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.
精彩评论