Remove DATE ONLY from datetime column

  • Sean Lange

    SSC Guru

    Points: 286482

    I would hope that nobody is actually still using SQL Server 2005. In 2008 (also no longer supported) the time datatype was introduced.

    This makes this type of thing so simple.


    select convert(time, getdate())

    _______________________________________________________________

    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/

  • Lynn Pettis

    SSC Guru

    Points: 442167

    Sean Lange - Friday, January 18, 2019 10:09 AM

    I would hope that nobody is actually still using SQL Server 2005. In 2008 (also no longer supported) the time datatype was introduced.

    This makes this type of thing so simple.


    select convert(time, getdate())

    I agree, but I would not be surprised if some where out there in the wild there are still people and organizations using not only SQL Server 2005 but 2000, 7.5, 7.0, 6.5, 6.0.  If they are out there, they still need our help.

  • Sean Lange

    SSC Guru

    Points: 286482

    Lynn Pettis - Friday, January 18, 2019 11:24 AM

    Sean Lange - Friday, January 18, 2019 10:09 AM

    I would hope that nobody is actually still using SQL Server 2005. In 2008 (also no longer supported) the time datatype was introduced.

    This makes this type of thing so simple.


    select convert(time, getdate())

    I agree, but I would not be surprised if some where out there in the wild there are still people and organizations using not only SQL Server 2005 but 2000, 7.5, 7.0, 6.5, 6.0.  If they are out there, they still need our help.

    Indeed. But at the same time I would hate for somebody using 2017 to stumble across and use a now seriously out of date (pun intended) method. 🙂

    _______________________________________________________________

    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/

  • Jeff Moden

    SSC Guru

    Points: 995109

    Sean Lange - Friday, January 18, 2019 1:34 PM

    Lynn Pettis - Friday, January 18, 2019 11:24 AM

    Sean Lange - Friday, January 18, 2019 10:09 AM

    I would hope that nobody is actually still using SQL Server 2005. In 2008 (also no longer supported) the time datatype was introduced.

    This makes this type of thing so simple.


    select convert(time, getdate())

    I agree, but I would not be surprised if some where out there in the wild there are still people and organizations using not only SQL Server 2005 but 2000, 7.5, 7.0, 6.5, 6.0.  If they are out there, they still need our help.

    Indeed. But at the same time I would hate for somebody using 2017 to stumble across and use a now seriously out of date (pun intended) method. 🙂

    Since it's for display purposes, what's wrong with using CONVERT in 2017?

    --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.
    "If you think its expensive to hire a professional to do the job, wait until you hire an amateur."--Red Adair
    "Change is inevitable... change for the better is not."
    When you put the right degree of spin on it, the number 3|8 is also a glyph that describes the nature of a DBAs job. 😉

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

  • Lempster

    SSCoach

    Points: 15529

    Lynn Pettis - Friday, January 18, 2019 9:38 AM

    Lempster - Friday, January 18, 2019 2:26 AM

    Really?  What about this:
    SELECT CONVERT(varchar(10),GETDATE(),108);

    @Lynn Pettis: I did say that were probably other ways to achieve what the OP wanted!

  • Jeff Moden

    SSC Guru

    Points: 995109

    Lempster - Saturday, January 19, 2019 1:43 AM

    Lynn Pettis - Friday, January 18, 2019 9:38 AM

    Lempster - Friday, January 18, 2019 2:26 AM

    Really?  What about this:
    SELECT CONVERT(varchar(10),GETDATE(),108);

    @Lynn Pettis: I did say that were probably other ways to achieve what the OP wanted!

    It was likely the words "you'll need to" that Lynn is taking exception to,  I was thinking the same thing as he. 😀  It's things like this that have made me change my posting style a bit over the last couple of decades just to keep people from becoming incensed by words whether they're right or wrong to do so.  For example, I'd have written "Here's one way to do it...".

    Now, what would really be cool would be if you two guys got together and did a million row test on your machines and published your results and the code on this thread so other people can do the same. :laugh:

    --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.
    "If you think its expensive to hire a professional to do the job, wait until you hire an amateur."--Red Adair
    "Change is inevitable... change for the better is not."
    When you put the right degree of spin on it, the number 3|8 is also a glyph that describes the nature of a DBAs job. 😉

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

  • Lempster

    SSCoach

    Points: 15529

    Jeff Moden - Saturday, January 19, 2019 3:02 PM

    Lempster - Saturday, January 19, 2019 1:43 AM

    Lynn Pettis - Friday, January 18, 2019 9:38 AM

    It was likely the words "you'll need to" that Lynn is taking exception to,  I was thinking the same thing as he. 😀  It's things like this that have made me change my posting style a bit over the last couple of decades just to keep people from becoming incensed by words whether they're right or wrong to do so.  For example, I'd have written "Here's one way to do it...".

    Now, what would really be cool would be if you two guys got together and did a million row test on your machines and published your results and the code on this thread so other people can do the same. :laugh:

    Fair point Jeff. If I find the time to do the test you suggest, I will.

    Lempster

  • Jeff Moden

    SSC Guru

    Points: 995109

    Lempster - Sunday, January 20, 2019 2:31 AM

    Jeff Moden - Saturday, January 19, 2019 3:02 PM

    Lempster - Saturday, January 19, 2019 1:43 AM

    Lynn Pettis - Friday, January 18, 2019 9:38 AM

    It was likely the words "you'll need to" that Lynn is taking exception to,  I was thinking the same thing as he. 😀  It's things like this that have made me change my posting style a bit over the last couple of decades just to keep people from becoming incensed by words whether they're right or wrong to do so.  For example, I'd have written "Here's one way to do it...".

    Now, what would really be cool would be if you two guys got together and did a million row test on your machines and published your results and the code on this thread so other people can do the same. :laugh:

    Fair point Jeff. If I find the time to do the test you suggest, I will.

    Lempster

    Thank you, good Sir, for taking all of that the right way.  Both of you have your hearts in the right place.

    --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.
    "If you think its expensive to hire a professional to do the job, wait until you hire an amateur."--Red Adair
    "Change is inevitable... change for the better is not."
    When you put the right degree of spin on it, the number 3|8 is also a glyph that describes the nature of a DBAs job. 😉

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

Viewing 8 posts - 16 through 23 (of 23 total)

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