Having a not so bright moment

  • I want to pull in the current days date in the following format:

    2006-10-03 00:00:00

    or something similiar, but for the life of me, I can't remember how, the closest I have gotten is :

    Select convert(datetime,Getdate(),(110))

    What am I missing?

  • Try this

    Select convert(smalldatetime,Getdate(),(110))

     

    Prasad Bhogadi
    www.inforaise.com

  • I am trying to get rid of the time stamp at the end, that does not do it .

  • Select convert(VARCHAR(10),Getdate(),(121))

     

    Prasad Bhogadi
    www.inforaise.com

  • Or precisely if you want it in Datetime datatype

    Select CAST(convert(VARCHAR(10),Getdate(),(121)) AS SMALLDATETIME)

     

    Prasad Bhogadi
    www.inforaise.com

  • Perfect, thank you.

  • Conversions are a bit costly performance wise... the following works approximately 45% faster on a million row test...

     SELECT DATEADD(dd,DATEDIFF(dd,0,GETDATE()),0)

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

  • I completely Concur with Jeff's solution. Its better to avoid conversions and go with Jeff's solution.

     

    Prasad Bhogadi
    www.inforaise.com

  • Looks like I'm not the only one that can't sleep... thanks, Prasad.

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

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