GETDATE()

  • Greetings follks. I use the getdate function for countless transactions. It always shows the date, hours, and minutes, but not the seconds. Is there a way to get it to display the seconds? Could it have to do with my datefields, which are all smalldatetime?

    Greg

    Greg
    _________________________________________________________________________________________________
    The glass is at one half capacity: nothing more, nothing less.

  • Yes. Smalldatetime only tracks to the minute level

    Toni

  • Could it be to do with your regional settings? What happens if you do SELECT CAST (GETDATE() AS datetime)?

    John

  • John Mitchell (1/8/2008)


    Could it be to do with your regional settings? What happens if you do SELECT CAST (GETDATE() AS datetime)?

    John

    If I do that I get seconds and miliseconds. If smalldatetime only tracks to the minute, why are my dates like this '2008-01-08 11:25:00'? It seems to have a place for the seconds, but they are always '00'.

    Greg

    Greg
    _________________________________________________________________________________________________
    The glass is at one half capacity: nothing more, nothing less.

  • Greg Snidow (1/8/2008)


    John Mitchell (1/8/2008)


    Could it be to do with your regional settings? What happens if you do SELECT CAST (GETDATE() AS datetime)?

    John

    If I do that I get seconds and miliseconds. If smalldatetime only tracks to the minute, why are my dates like this '2008-01-08 11:25:00'? It seems to have a place for the seconds, but they are always '00'.

    Greg

    That is just the way it is displayed by Query Analyzer; notice that the minutes are always shown as 00.

    Internally, smalldatetime values are stored in a binary format with 2 bytes for the date and 2 bytes for the time. The maximum number of unique values in 2 bytes is 65,536, so that is not enough to hold the 86,400 seconds in a day.

  • Thanks for the info. I guess the extra storage space is not worth having visibility of the seconds for most of my applications.

    Greg

    Greg
    _________________________________________________________________________________________________
    The glass is at one half capacity: nothing more, nothing less.

  • Heh... "It Depends" 😉

    --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 7 posts - 1 through 6 (of 6 total)

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