SQL: Don't use abbreviations in T-SQL datetime intervals

I don't like seeing abbreviations used when there's no need to have them. Abbreviations can be overused and many times they're cryptic. Worse, I often see them applied inconsistently.

In general, I try to avoid abbreviations unless they are on a tight list of ones that I use all the time.

A pet dislike of mine is seeing them used (even if consistently) for interval values in T-SQL functions like DATEADD, DATEDIFF, etc.

In the list above, please use the name of the interval rather than the abbreviation. Don't have people wondering if:

means "week" or "weekday", or if "m" means "minute" or "millisecond".

If you mean "week", just write this:

And if you mean "weekday", just write this:

At least you'll remove all doubt about what you meant.

Make your code easy to read and understand.

 

 

2 thoughts on “SQL: Don't use abbreviations in T-SQL datetime intervals”

  1. I agree! Just to emphasise the confusion that it can cause, even the great Greg Low made a mistake here. "w" is "weekday" so the example should be "DATEADD(weekday, 2, SYSDATETIME())"

    🙂

    1. HI Dave, I wasn't meaning the two to be equivalent. Each was a separate example. But can see it could be read that way. I've clarified it. Thanks.

Leave a Reply

Your email address will not be published.