Remove DATE ONLY from datetime column

  • 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/

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

  • 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/

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

    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)

  • 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!

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

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

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

    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)

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

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