question

nik180 avatar image
nik180 asked

DateTime Procedure SQL SERVER

Hi guys . Have Procedure where i get last date > SELECT * FROM BalanceSessionData where > Date =(SELECT MAX(Date) FROM > BalanceSessionData) Now i need current date with my last date an if left 10 minutes from last date print'ok' For Example need something like : > declare @myDate datetime > > @myDate = GETDATE() - Date
sql-serverproceduredate-formatresultset from variable
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

·
Grant Fritchey avatar image
Grant Fritchey answered
If I understand what you mean, then you want to look at Date math. You can use [DATEADD][1] to add a particular value to a particular part of a date time. So for 10 minutes you can do this: DATEADD('mi',-10,GETDATE()) That will take 10 minutes off the current datetime. You can substitute a variable with GETDATE(). If you substitute a column in your table, know that running functions against a column in a WHERE clause can lead to scans. [1]: http://msdn.microsoft.com/en-US/library/ms186819(v=sql.110).aspx
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.