Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

T-SQL : Using { fn NOW() } in WHERE

I was reviewing some SQL queries and I saw a select statement that looked like this

SELECT *
FROM dbo.mytable
WHERE (dbo.mytable.[Date] < { fn NOW() })

What is the purpose of using a WHERE statement like this?

Wouldn't be easier to use a simple GETDATE()?

like image 813
Pascal Paradis Avatar asked Nov 10 '08 18:11

Pascal Paradis


1 Answers

http://www.sqlservercentral.com/Forums/Topic183904-8-1.aspx

GETDATE() is a T-SQL specific function which returns the current system date and time. The SQL standard equivalent is CURRENT_TIMESTAMP which is applicable in T-SQL as well. The {fn Now()} is an ODBC canonical function which can be used in T-SQL since the OLE DB provider for SQL Server supports them. There are no notable performance difference between these though. You can also use canonical format like :

SELECT {fn CURRENT_TIMESTAMP()} AS "date & time",
       {fn CURRENT_DATE()} AS "date only",
       {fn CURRENT_TIME()} AS "time only" ; 
like image 151
LeppyR64 Avatar answered Oct 21 '22 01:10

LeppyR64