DY

  • Comments posted to this topic are about the item DY

  • This was removed by the editor as SPAM

  • Hi Steve,

    I think the answer should state that it is a lot safer to just write "DayOfYear" in your code.

    This also makes the code easier to read.

    Best regards,

    Henrik

  • There is debate over which form to use - the full or abbreviation. The cool part is that both work. 😉

  • Ed Wagner (11/6/2015)


    There is debate over which form to use - the full or abbreviation. The cool part is that both work. 😉

    Cool part? Or Dangerous part? Too easy to type "dy" when you mean "day" or vice versa.

    Gerald Britton, Pluralsight courses

  • henrik staun poulsen (11/6/2015)


    Hi Steve,

    I think the answer should state that it is a lot safer to just write "DayOfYear" in your code.

    This also makes the code easier to read.

    Best regards,

    Henrik

    How is it safer? Both options will work exactly the same. Sometimes is easier to read if you constantly use 2 letters to define the date part. Works great when you have lengthy code.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Aaron Bertrand had a nice blog about this: scroll down for "Pop Quiz" and see if you still think DATEPART abbreviations are straightforward.

    Rich

  • g.britton (11/6/2015)


    Ed Wagner (11/6/2015)


    There is debate over which form to use - the full or abbreviation. The cool part is that both work. 😉

    Cool part? Or Dangerous part? Too easy to type "dy" when you mean "day" or vice versa.

    Well, I guess it depends on what you're used to using. Personally, I like using the long form, but some people prefer using the short form. Like I said before, they both work.

  • Good question Steve.

    Count me as being in the camp for long hand. I am entirely too scatter brained to remember all the abbreviations. Even the common ones make me stop and think about it.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Ha - thought this was so easy there must be a trick about conversion.

    Should have realised Steve wouldn't do that.

    No points.

  • Rich Mechaber (11/6/2015)


    Aaron Bertrand had a nice blog about this: scroll down for "Pop Quiz" and see if you still think DATEPART abbreviations are straightforward.

    Rich

    2 letter abbreviations are straightforward, single letter are not. With the exception of 2 options that don't have a 2 letter abbreviation (microsecond which could be US as a representation of µs, and iso week which could be IW as in :sick:Oracle:sick:), all can have a standard length and in most of the cases it matches the amount of digits required.

    How is it difficult to remember this: YYYY-MM-DD hh:mi:ss.ms tz ?

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Luis Cazares (11/6/2015)


    Rich Mechaber (11/6/2015)


    Aaron Bertrand had a nice blog about this: scroll down for "Pop Quiz" and see if you still think DATEPART abbreviations are straightforward.

    Rich

    2 letter abbreviations are straightforward, single letter are not. With the exception of 2 options that don't have a 2 letter abbreviation (microsecond which could be US as a representation of µs, and iso week which could be IW as in :sick:Oracle:sick:), all can have a standard length and in most of the cases it matches the amount of digits required.

    How is it difficult to remember this: YYYY-MM-DD hh:mi:ss.ms tz ?

    The 2 letter abbreviations are better but some of them are still difficult to remember. dw for weekday is a good example. And dd for day instead of dy is a little off but of course that is because dy is for dayofyear. And microsecond just doesn't have a reasonable 2 character shortcut. When reading code I can usually get it right but I have to stop and look at it. In the middle of a bunch of code dw is not nearly as easy to remember as weekday. It of course boils down to preference. I have to say that for so many people who don't mind the extra characters to be clear and precise for things like never leaving off the schema it seems contrary when the argument is made to use abbreviations for date parts. Just my 2¢.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Sean Lange (11/6/2015)


    Luis Cazares (11/6/2015)


    Rich Mechaber (11/6/2015)


    Aaron Bertrand had a nice blog about this: scroll down for "Pop Quiz" and see if you still think DATEPART abbreviations are straightforward.

    Rich

    2 letter abbreviations are straightforward, single letter are not. With the exception of 2 options that don't have a 2 letter abbreviation (microsecond which could be US as a representation of µs, and iso week which could be IW as in :sick:Oracle:sick:), all can have a standard length and in most of the cases it matches the amount of digits required.

    How is it difficult to remember this: YYYY-MM-DD hh:mi:ss.ms tz ?

    The 2 letter abbreviations are better but some of them are still difficult to remember. dw for weekday is a good example. And dd for day instead of dy is a little off but of course that is because dy is for dayofyear. And microsecond just doesn't have a reasonable 2 character shortcut. When reading code I can usually get it right but I have to stop and look at it. In the middle of a bunch of code dw is not nearly as easy to remember as weekday. It of course boils down to preference. I have to say that for so many people who don't mind the extra characters to be clear and precise for things like never leaving off the schema it seems contrary when the argument is made to use abbreviations for date parts. Just my 2¢.

    I'm not saying that using 2 letter abbreviations is the correct way to go. I won't correct code to use one or the other. I just don't get that people say that abbreviations should be avoided because they're dangerous.

    It's one of those things that just will keep as a constant debate, such as leading commas and trailing commas. And no, I don't want to start a debate on that. 😀

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Luis Cazares (11/6/2015)


    Rich Mechaber (11/6/2015)


    Aaron Bertrand had a nice blog about this: scroll down for "Pop Quiz" and see if you still think DATEPART abbreviations are straightforward.

    Rich

    2 letter abbreviations are straightforward, single letter are not. With the exception of 2 options that don't have a 2 letter abbreviation (microsecond which could be US as a representation of µs, and iso week which could be IW as in :sick:Oracle:sick:), all can have a standard length and in most of the cases it matches the amount of digits required.

    How is it difficult to remember this: YYYY-MM-DD hh:mi:ss.ms tz ?

    Well, it looks like you forgot dw, dy, wk, ww, qq, and ns...

    What if you're sharing your code with absolutely anybody else? Odds are much higher they will know the difference between, for example, "day", "weekday", and "dayofyear" than "dd", "dw", and "dy".

  • sknox (11/6/2015)


    Luis Cazares (11/6/2015)


    Rich Mechaber (11/6/2015)


    Aaron Bertrand had a nice blog about this: scroll down for "Pop Quiz" and see if you still think DATEPART abbreviations are straightforward.

    Rich

    2 letter abbreviations are straightforward, single letter are not. With the exception of 2 options that don't have a 2 letter abbreviation (microsecond which could be US as a representation of µs, and iso week which could be IW as in :sick:Oracle:sick:), all can have a standard length and in most of the cases it matches the amount of digits required.

    How is it difficult to remember this: YYYY-MM-DD hh:mi:ss.ms tz ?

    Well, it looks like you forgot dw, dy, wk, ww, qq, and ns...

    What if you're sharing your code with absolutely anybody else? Odds are much higher they will know the difference between, for example, "day", "weekday", and "dayofyear" than "dd", "dw", and "dy".

    Aren't those self explanatory? If they don't know the difference, selecting the function and pressing F1 will take them to the page on BOL. Since DD is a standard across all the systems that I've used to represent the day, I don't get where's the confusion. Only someone with absolutely no experience on IT would use dy as a representation of day.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 15 posts - 1 through 15 (of 40 total)

You must be logged in to reply to this topic. Login to reply