SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


GETDATE() -vs- fn NOW()


GETDATE() -vs- fn NOW()

Author
Message
Bob Bridges-173967
Bob Bridges-173967
Old Hand
Old Hand (338 reputation)Old Hand (338 reputation)Old Hand (338 reputation)Old Hand (338 reputation)Old Hand (338 reputation)Old Hand (338 reputation)Old Hand (338 reputation)Old Hand (338 reputation)

Group: General Forum Members
Points: 338 Visits: 350

Can someone help me understand when it is better to use GETDATE() as opposed to fn NOW()?

I obviously get the same result when I run them in Query Analyzer but I can't find any documentation concerning when you should use one over the other.

Thanks,

Bob Bridges


Ninja's_RGR'us
Ninja's_RGR'us
SSC Guru
SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)

Group: General Forum Members
Points: 64463 Visits: 9671
Actually now() is not a standard sql function.. are you sure that now is note a view or a user defined function that returns the getdate() value??
Bob Bridges-173967
Bob Bridges-173967
Old Hand
Old Hand (338 reputation)Old Hand (338 reputation)Old Hand (338 reputation)Old Hand (338 reputation)Old Hand (338 reputation)Old Hand (338 reputation)Old Hand (338 reputation)Old Hand (338 reputation)

Group: General Forum Members
Points: 338 Visits: 350

In Query Analyzer, I get the exact same results from the following two queries...

SELECT {fn NOW()}

SELECT GETDATE()


ron k
ron k
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1361 Visits: 5

Using sql server 2000

Select Now()

------------------------
Server: Msg 195, Level 15, State 10, Line 1
'now' is not a recognized function name.


ron k
ron k
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1361 Visits: 5

...And so do I ?


Ninja's_RGR'us
Ninja's_RGR'us
SSC Guru
SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)

Group: General Forum Members
Points: 64463 Visits: 9671
I agree that it returns the same thing.. but I can't find any reference of it in the books online nor yahoo... So I guess it's an undocumented command that returns the date. So that would be my reason not to use it .
sushila
sushila
SSCrazy Eights
SSCrazy Eights (8.1K reputation)SSCrazy Eights (8.1K reputation)SSCrazy Eights (8.1K reputation)SSCrazy Eights (8.1K reputation)SSCrazy Eights (8.1K reputation)SSCrazy Eights (8.1K reputation)SSCrazy Eights (8.1K reputation)SSCrazy Eights (8.1K reputation)

Group: General Forum Members
Points: 8073 Visits: 639
Here's something my googling fished out...

Conversion of "NOW()" Access datatype in SQL Server 2000 datatype - GETDATE()







**ASCII stupid question, get a stupid ANSI !!!**
sushila
sushila
SSCrazy Eights
SSCrazy Eights (8.1K reputation)SSCrazy Eights (8.1K reputation)SSCrazy Eights (8.1K reputation)SSCrazy Eights (8.1K reputation)SSCrazy Eights (8.1K reputation)SSCrazy Eights (8.1K reputation)SSCrazy Eights (8.1K reputation)SSCrazy Eights (8.1K reputation)

Group: General Forum Members
Points: 8073 Visits: 639
Don't know why it says datatype and not function though...

Don't shoot - I'm only the messenger!







**ASCII stupid question, get a stupid ANSI !!!**
Michael Du Bois
Michael Du Bois
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1235 Visits: 1

Now() is used in both EXCEL and ACCESS to return the current date and time.

But it is undocumented in T-SQL a sure road to trouble.

HTH Mike


ron k
ron k
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1361 Visits: 5

In addition to several replies advising to stay away from such undocumented features I did get this reply to my post on a ms newsgroup:


Anith Sen Jul 14 2003, 4:02 pm show options

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" ;


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search