r/SQL • • Sep 25 '26

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()?

7 Upvotes

19 comments sorted by

View all comments

1

u/KBradl Sep 25 '26

I have never seen that or done it. They values are the same so it seems superflous.

Maybe its one of those things people do to make things look more complex. I once ran into some code that had If 1 = 1 all over the place.

4

u/Malfuncti0n Sep 25 '26

If 1=1 makes much sense if you are debugging or building in blocks, so you can quickly skip over large parts just by changing the If instead of commenting the entire thing out.

2

u/Substantial-Book2534 Sep 25 '26

1=1 in the Where clause also grinds my gears. 😠

2

u/Username928351 Sep 25 '26

If I'm working on a query and need to comment out the first WHERE clause, this way I don't have to rewrite the AND after it into a WHERE.

2

u/Yavuz_Selim Sep 25 '26

I use 'WHERE 1 = 1' all the time.

Makes testing and debugging much easier. No need to rewrite anything, just comment out or add new lines to the WHERE.

It's like adding the comma at the front instead of at the end. Personal preference.

1

u/crippling_altacct Sep 25 '26

Man seeing a comma at the end really grinds my gears.