August 2, 2006 at 5:17 am
Working from memory here, so make sure you retest this.
DateAdd(D, 0, Datediff(D, 0, GetDate()))
This should strip out the time part of the date and give the correct results.
August 2, 2006 at 6:10 am
GETDATE() is not a date. It's current moment of time. With precision of 3ms.
">= GETDATE()" means now or in future. Everything wat happened today before now is the past and not gonna be included.
_____________
Code for TallyGenerator
August 2, 2006 at 6:39 am
Got It Working! All I did was " >= GETDATE() - 1 "! Any reason I shouldn't Use this?
August 2, 2006 at 6:53 am
GETDATE() - 1 is actually 24 hours ago. So,it's everything happend after same time yesterday.
Any reason you shouldn't use this? You know better.
If you need start of today's day use dateadd(dd, datediff(dd, 0, GETDATE()), 0)
_____________
Code for TallyGenerator
August 2, 2006 at 7:54 am
No you didn't... make sure you test a lot when dates are included in the where predicates. It's easy to get bitten by them.
June 4, 2010 at 6:14 am
Not only the {fn now() }, some other functions which are from VB also supported ( actually its from MACRO )
Example :
{fn Hour(getdate()) }
July 3, 2010 at 6:06 pm
Aren't those just ODBC functions?
--Jeff Moden
Change is inevitable... Change for the better is not.
October 27, 2010 at 4:42 am
if u are migrating data from Sql Server to My SQL.U need to change function like GETDATE() to NOW().SQL Server uses GETDATE() function to show current date time in proper format.and NOW() is used for MY SQL to show current date time in format YYYY-MM-DD........HH:...
May 11, 2016 at 12:53 pm
There are three ways to retrieve the current datetime in SQL SERVER.
CURRENT_TIMESTAMP, GETDATE(), {fn NOW()}
CURRENT_TIMESTAMP
CURRENT_TIMESTAMP is a nondeterministic function. Views and expressions that reference this column cannot be indexed. CURRENT_TIMESTAMP can be used to print the current date and time every time that the report is produced.
GETDATE()
GETDATE is a nondeterministic function. Views and expressions that reference this column cannot be indexed. GETDATE can be used to print the current date and time every time that the report is produced.
{fn Now()}
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. {fn Now()} can be used to print the current date and time every time that the report is produced.
If you run following script in Query Analyzer. I will give you same results. If you see execution plan there is no performance difference. It is same for all the three select statement.
SELECT CURRENT_TIMESTAMP
GO
SELECT {fn NOW()}
GO
SELECT GETDATE()
GO
Performance:
There is absolutely no difference in using any of them. As they are absolutely same.
May 11, 2016 at 1:16 pm
if you include the fn now function, there are seven ways i know of to get the current datetime; there's a few threads around that points out that a potential candidate should know how to get the current datetime, and anyone with a bit of expereince should know there's more.
I believe there is at least one dmv you can select a column from that returns the datetime too, but i don't remember offhand.
SELECT CURRENT_TIMESTAMP,
{fn NOW()},
Getdate(),
Getutcdate(),
SYSDATETIME(),
SYSUTCDATETIME(),
SYSDATETIMEOFFSET()
Lowell
Viewing 10 posts - 16 through 24 (of 24 total)
You must be logged in to reply to this topic. Login to reply