GETDATE() -vs- fn NOW()

  • 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.

  • 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

  • Got It Working! All I did was " >= GETDATE() - 1 "! Any reason I shouldn't Use this?

  • 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

  • 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.

  • Not only the {fn now() }, some other functions which are from VB also supported ( actually its from MACRO )

    Example :

    {fn Hour(getdate()) }

  • Aren't those just ODBC functions?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • 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:...

  • 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.

    Courtesy :http://blog.sqlauthority.com/2007/06/21/sql-server-retrieve-current-date-time-in-sql-server-current_timestamp-getdate-fn-now/%5B/b%5D

  • 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


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 10 posts - 16 through 24 (of 24 total)

You must be logged in to reply to this topic. Login to reply