DATEDIFF Question

  • Hi

    Can anyone tell me what the 0 does in the following:

    SELECT DATEDIFF(m, 0, '01/01/2011');

    Does it indicate the start of time as far as SQL goes and if so what is it?

    Thanks

  • Kwisatz78 (12/1/2011)


    Hi

    Can anyone tell me what the 0 does in the following:

    SELECT DATEDIFF(m, 0, '01/01/2011');

    Does it indicate the start of time as far as SQL goes and if so what is it?

    Thanks

    It indicates '1900-01-01 00:00:00'

    SELECT CAST(0 AS DATETIME)

    Bear in mind that this isn't the start of time as SQL sees it, e.g. try this

    SELECT CAST(-1 AS DATETIME)


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • Ahh many thanks

  • You can actually change the zero date at a server-level, so test it before you count on that. Won't matter if it's being used to strip parts off of dates (like midnight calculations or 1st of month calculations), but might matter if it's being used for something else.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • GSquared (12/1/2011)


    You can actually change the zero date at a server-level, so test it before you count on that. Won't matter if it's being used to strip parts off of dates (like midnight calculations or 1st of month calculations), but might matter if it's being used for something else.

    Wow, wasn't aware you could change it! Going to have to change some of the hacks I've had to do due to the lack of a calendar table, thanks 😛


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

Viewing 5 posts - 1 through 5 (of 5 total)

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