can we add a number directly in datetime variable in sql server -


i have variable @var1 date time

will below query work set @var1 = @var1 +1

i want increment date 1 in @var1

will above method or dateadd(dd,1,@var1) more efficent

(even if syntactically valid, not obvious next person reads code happening).

in platforms, date-and-time values radixed on day, x + 1 next calendar day, , fractional day number of seconds or minutes.

other platforms store or represent date-and-time values integer seconds (or miliseconds, or nanoseconds) since epoch value, in case x + 1 adds 1 second or whatever base unit value.

for best results (consistent on every platform, , obvious) use platform's built-in date library. in sql dateadd function, specify quantity want add date.

your question asks if + 1 or dateadd "more efficient". i'll don't use sql "efficient" - there inherent inefficiencies in sql , database systems; can said developer productivity , bug-avoidance far more important, in case should use dateadd.


Comments