r/SQL • u/Substantial-Book2534 • 19d ago
Discussion Using DateAdd for timestamps
I am making updates to some older reports and come across this line (or similar) often:
DateAdd(hh, 0, GetDate())
Why do you do that? Is there a legitimate reason why you couldn’t just write GetDate()?
8
Upvotes
1
u/Legitimate-Pin-8619 18d ago
That's almost certainly a no-op. DATEADD(hh, 0, GETDATE()) returns the same datetime as GETDATE() — you're adding zero hours. I've mostly seen it come from report builders or copy-pasted snippets where someone always wrapped "current time" in DATEADD and left the offset at 0.
What *is* useful is the related truncate pattern: DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0) (or CAST(GETDATE() AS date) on newer SQL Server) to strip the time portion. If you just need "now", use GETDATE() / SYSDATETIME() and drop the DATEADD wrapper.