Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 123»»»

GETDATE() -vs- fn NOW() Expand / Collapse
Author
Message
Posted Thursday, May 19, 2005 1:36 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, March 7, 2013 6:16 AM
Points: 90, 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

Post #183904
Posted Thursday, May 19, 2005 1:57 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 4:00 AM
Points: 21,397, Visits: 9,612
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??
Post #183913
Posted Thursday, May 19, 2005 2:27 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, March 7, 2013 6:16 AM
Points: 90, Visits: 350

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

SELECT {fn NOW()}

SELECT GETDATE()

Post #183922
Posted Thursday, May 19, 2005 2:30 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, May 8, 2009 7:56 PM
Points: 361, Visits: 5

Using sql server 2000

Select Now()

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

Post #183923
Posted Thursday, May 19, 2005 2:32 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, May 8, 2009 7:56 PM
Points: 361, Visits: 5

...And so do I ?

 

Post #183924
Posted Thursday, May 19, 2005 2:33 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 4:00 AM
Points: 21,397, Visits: 9,612
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 .
Post #183925
Posted Thursday, May 19, 2005 2:55 PM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, August 18, 2014 8:49 AM
Points: 2,553, Visits: 578
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 !!!**
Post #183933
Posted Thursday, May 19, 2005 3:10 PM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, August 18, 2014 8:49 AM
Points: 2,553, Visits: 578
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 !!!**
Post #183936
Posted Thursday, May 19, 2005 3:31 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Saturday, May 20, 2006 9:25 PM
Points: 383, 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

Post #183943
Posted Thursday, May 19, 2005 5:37 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, May 8, 2009 7:56 PM
Points: 361, 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" ;

 

Post #183958
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse