Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select DATEADD minutes with query SQL Server 2008

How can I add minutes using dateadd() with a query result ?

Like this:

SELECT dateadd(minute, (SELECT 
                isnull(time1 - time2, 0)
                FROM table 
                WHERE field = 111) , getdate())

In this case, the select result is 288 but it don't add

I need ADD this 288 in the function

Like this:

SELECT dateadd(minute, 288, getdate())
like image 337
soamazing Avatar asked Jan 24 '12 14:01

soamazing


1 Answers

SELECT DATEADD(MINUTE, DATEDIFF(MINUTE, time1, time2), GETDATE())
FROM table
WHERE field = 111

This will add difference in minutes between time1 and time2 to current date, if that's what you want to achieve.

like image 63
el ninho Avatar answered Sep 25 '22 14:09

el ninho