DY

  • Easy one, thanks.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • That was an easy one, thanks.

  • 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

    Good suggestion, thanks.

  • Jeff Moden (11/6/2015)


    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".

    To be honest, if they haven't taken the time to learn something so simple, they're in the wrong bloody business.

    Looks like my link to Aaron Bertrand's blog provoked some conversation. Good.

    I'm not advocating for one approach over another. My goal was to underscore that the "standard" abbreviations for date/time components aren't always obvious and can lead to confusion.

    Oh well, I guess I'll need to brush up my resume and seek a new profession now. Apparently my inability to remember that weekday is abbreviated "dw" and not "wd" has left me unfit for a career in IT.

    I've mastered the use of dust-off to dislodge crumbs and other bric-a-brac from within keyboards: is that a marketable skill?

    Rich

  • Rich Mechaber (11/9/2015)


    Jeff Moden (11/6/2015)


    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".

    To be honest, if they haven't taken the time to learn something so simple, they're in the wrong bloody business.

    Looks like my link to Aaron Bertrand's blog provoked some conversation. Good.

    I'm not advocating for one approach over another. My goal was to underscore that the "standard" abbreviations for date/time components aren't always obvious and can lead to confusion.

    Oh well, I guess I'll need to brush up my resume and seek a new profession now. Apparently my inability to remember that weekday is abbreviated "dw" and not "wd" has left me unfit for a career in IT.

    I've mastered the use of dust-off to dislodge crumbs and other bric-a-brac from within keyboards: is that a marketable skill?

    Rich

    Ah... sorry Rich. I didn't mean to be such a snot about all of this. I just can't believe that anyone calling the use of mostly standard abbreviations a "bad habit to kick" or a "worst practice" never mind write a highly opinionated section of a article on such things. :sick:

    BTW... proper inversion of a keyboard and shaking it vigorously is a much sought after skill. ๐Ÿ˜€

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff Moden (11/9/2015)


    Rich Mechaber (11/9/2015)


    Jeff Moden (11/6/2015)


    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".

    To be honest, if they haven't taken the time to learn something so simple, they're in the wrong bloody business.

    Looks like my link to Aaron Bertrand's blog provoked some conversation. Good.

    I'm not advocating for one approach over another. My goal was to underscore that the "standard" abbreviations for date/time components aren't always obvious and can lead to confusion.

    Oh well, I guess I'll need to brush up my resume and seek a new profession now. Apparently my inability to remember that weekday is abbreviated "dw" and not "wd" has left me unfit for a career in IT.

    I've mastered the use of dust-off to dislodge crumbs and other bric-a-brac from within keyboards: is that a marketable skill?

    Rich

    Ah... sorry Rich. I didn't mean to be such a snot about all of this. I just can't believe that anyone calling the use of mostly standard abbreviations a "bad habit to kick" or a "worst practice" never mind write a highly opinionated section of a article on such things. :sick:

    BTW... proper inversion of a keyboard and shaking it vigorously is a much sought after skill. ๐Ÿ˜€

    Hah, no harm, no foul Jeff. It's a curious fact that the least consequential choices in IT often generate the most vigorous, passionate arguments. Much like marriage, child-rearing, religion, and politics -- but with per-processor licensing.

    ๐Ÿ˜‰

    Rich

  • Jeff Moden (11/9/2015)


    Rich Mechaber (11/9/2015)


    Jeff Moden (11/6/2015)


    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".

    To be honest, if they haven't taken the time to learn something so simple, they're in the wrong bloody business.

    Looks like my link to Aaron Bertrand's blog provoked some conversation. Good.

    I'm not advocating for one approach over another. My goal was to underscore that the "standard" abbreviations for date/time components aren't always obvious and can lead to confusion.

    Oh well, I guess I'll need to brush up my resume and seek a new profession now. Apparently my inability to remember that weekday is abbreviated "dw" and not "wd" has left me unfit for a career in IT.

    I've mastered the use of dust-off to dislodge crumbs and other bric-a-brac from within keyboards: is that a marketable skill?

    Rich

    Ah... sorry Rich. I didn't mean to be such a snot about all of this. I just can't believe that anyone calling the use of mostly standard abbreviations a "bad habit to kick" or a "worst practice" never mind write a highly opinionated section of a article on such things. :sick:

    BTW... proper inversion of a keyboard and shaking it vigorously is a much sought after skill. ๐Ÿ˜€

    It isn't the first time this discussion has been around here. I remember one of them where Jeff basically stated I have no right to even turn on a computer. ๐Ÿ˜›

    This topic is highly opinionated and I agree that for the everyday abbreviations they are pretty simple. It is just that some of them are downright challenging to remember. I find that dd for day and dy for dayofweek are easy for me to get confused. I have to look those two up every single time I come across them. I am pretty sure that after almost 20 years I am just not going to remember them. ๐Ÿ˜‰

    I think this one really kind of boils down to the same discussion as naming conventions or code formatting. You should stick to the conventions in the environment where you work.

    _______________________________________________________________

    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/

  • sknox (11/6/2015)


    Luis Cazares (11/6/2015)


    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.

    Those two sentences are self-contradictory: If the terms were self-explanatory then by definition they would not need too be looked up; therefore the advice to look them up on BOL undermines your assertion that they are.

    How can a question and an affirmation be self-contradictory? I'm making the question because those are self explanatory for me, but if someone asks me what they mean, I can lead them to find the answer on their own.

    By the way, these should be easily understood by an English speaker (native or not), but I've had to deal with many colleagues that don't speak English and need to figure this out by going to BOL.

    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/9/2015)


    How can a question and an affirmation be self-contradictory? I'm making the question because those are self explanatory for me, but if someone asks me what they mean, I can lead them to find the answer on their own.

    By the way, these should be easily understood by an English speaker (native or not), but I've had to deal with many colleagues that don't speak English and need to figure this out by going to BOL.

    A rhetorical question is a statement in the form of a question, so you really do have two statements, not a question and a statement.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • drew.allen (11/9/2015)


    Luis Cazares (11/9/2015)


    How can a question and an affirmation be self-contradictory? I'm making the question because those are self explanatory for me, but if someone asks me what they mean, I can lead them to find the answer on their own.

    By the way, these should be easily understood by an English speaker (native or not), but I've had to deal with many colleagues that don't speak English and need to figure this out by going to BOL.

    A rhetorical question is a statement in the form of a question, so you really do have two statements, not a question and a statement.

    Drew

    Just a note:

    Extract from here


    Though a rhetorical question does not require a direct answer, in many cases it may be intended to start a discussion

    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
  • Rich Mechaber (11/9/2015)


    Oh well, I guess I'll need to brush up my resume and seek a new profession now. Apparently my inability to remember that weekday is abbreviated "dw" and not "wd" has left me unfit for a career in IT.

    Me too, it seems. Maybe I'll go build some space ships after all. ๐Ÿ˜€

    (though it's the 'mi' that catches me way too often. Either I can't remember it at all, or I use mm and wonder for a few moments why my results are several years wrong)

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 11 posts - 31 through 40 (of 40 total)

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