Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is GETDATE() expensive as DateTime.Now is?

I have heard that DateTime.Now is very expensive call (from here)

Is GETDATE() in SQL 2005/2008 expensive? Have I to cache it into a variable if my stored procedure uses it a number of times?

like image 755
abatishchev Avatar asked Sep 05 '09 12:09

abatishchev


People also ask

Is Getdate a datetime?

To get the current date and time in SQL Server, use the GETDATE() function. This function returns a datetime data type; in other words, it contains both the date and the time, e.g. 2019-08-20 10:22:34 .

Does Getdate () include time?

GETDATE returns the current date and time in the current session time zone (UTC by default). It returns the start date or time of the current statement, even when it is within a transaction block.

What does Getdate () mean?

The GETDATE() function returns the current database system date and time, in a 'YYYY-MM-DD hh:mm:ss.mmm' format.

What type is Getdate () SQL?

GETDATE (SQL) A date/time function that returns the current local date and time.


1 Answers

It's not expensive: it comes straight from the OS.

I'd cache it anyway. It will most likely be different for separate calls if you have multiple statements. Say you have multiple inserts, surely you'd want the value to correlate acrosss tables?

If it's use in a SELECT, say, for output then it's only evaluated once usually.

like image 144
gbn Avatar answered Oct 05 '22 15:10

gbn