how to add one second

  • Riddle me this batman...

    (and no I'm not the orginator of this discussion)

    What if you want the number of Seconds since some time period?

     

    Let say you want to know the number of seconds since 7/4/2004, what's the query?

  • That's unfair!

    select

     getdate()

     , datediff(ss,cast('7/4/2004' as datetime), getdate())%60

                                                                      

    ------------------------------------------------------ -----------

    2004-12-28 16:00:59.590                                59

    (1 row(s) affected)

    Now add 1 and get 0 => No time difference between both date. q.e.d.

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • How about this:

    DECLARE @dt datetime

    SET @dt = '7/4/2004'

    SELECT DateDiff(s, @dt, GetDate())

  • Why did you add % 60?  Second answer seems to work as expected.

     

    Happy New Year!

    Steve

  • Blame it on the language barrier. I thought, your question wasn't meant seriously. I guess I got confused by this "Riddle me this batman..." phrase.

    Anyway, happy new year, too.

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

Viewing 5 posts - 16 through 19 (of 19 total)

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