Today as a Serial Date

  • Hi,

    Does anyone know how I can return todays date in serial format from sql server ?

    Thanks,

    matt

  • see

    Previous Forum Thread

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • Hi,

    Thanks for the reply. I've had a look at the thread. I'm not sure it answers my question. I'm looking for the serial date like Excel produces, ie an integer representing the number of days since 1st Jan 1900. I need this as I am working with an application that records its dates in this format, and I was hoping that SQL Server had a similar function.

    Many thanks,

    Matt

  • Would the following give the expected result?

    SELECT DATEDIFF(dd,0,GETDATE())

    However, it's interesting that EXCEL returns 40062 for today (2009-09-06), but SQL Server returns 40060...



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • Thanks Lutz, this is exactly what I needed. The application uses the 0 date as Jan 1st 1801 so I have to do some conversion work anyway !

    Matt

  • lmu92 (9/6/2009)


    Would the following give the expected result?

    SELECT DATEDIFF(dd,0,GETDATE())

    However, it's interesting that EXCEL returns 40062 for today (2009-09-06), but SQL Server returns 40060...

    The "0" date for for the default date serial numbers behind the scenes in Excel isn't 01/01/1900... it 12/31/1899. Further, Excel thinks that 2/29/1900 was a valid date (ccan you believe they still haven't fixed this stuff even after y2k happened???? :-P)

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

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