Fun with Time

  • Comments posted to this topic are about the item Fun with Time

  • Nice, easy question, thanks Steve

    ____________________________________________
    Space, the final frontier? not any more...
    All limits henceforth are self-imposed.
    β€œlibera tute vulgaris ex”

  • Should i drink a second coffee? :crazy:

  • palotaiarpad - Tuesday, February 28, 2017 2:08 AM

    Should i drink a second coffee? :crazy:

    @t is TIME, not DATETIME. That's what got me.

    The explanation for this question is severely lacking in actual explanation.

  • I have to agree with sknox. This is a great question but I didn't actually understand the question until I read his comment. I too missed that it was a TIME datatype and was seriously confused.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Thanks Steve for this question, yes I had a "Fun with Time", but it cost me just a little time.πŸ™‚


    DECLARE @t TIME = GETDATE();
    SELECT DATEDIFF(MINUTE, 0, @t);
    --=============================================
    --"Have fun with TIME", my subsequent attempts:
    --=============================================
    -- getdate() datetime value is implicitly converted to hh:mm:ss.nnnnnn
    -- MSDN time (Transact-SQL), CAST and CONVERT (Transact-SQL)
    SELECT @t;
    -- If only a time value is assigned to a variable of a date data type, 
    -- the value of the missing date part is set to the default value: 1900-01-01.
    SELECT DATEDIFF(MINUTE, '1900-01-01 00:00:00', @t);
    -- startdate 0 is set to default value, enddate @t time value is set to 1900-01-01 hh:mm:ss
    SELECT DATEDIFF(MINUTE, GETDATE(), @t);
    SELECT DATEDIFF(MINUTE, @t, GETDATE());
    SELECT DATEDIFF(MINUTE, @t, @t);
    SELECT DATEADD(MINUTE,0, @t);
    SELECT DATEDIFF(MINUTE, '1900-01-01 00:00:00', dateadd(MINUTE,0, @t));

  • George Vobr - Tuesday, February 28, 2017 9:29 AM

    Thanks Steve for this question, yes I had a "Fun with Time", but it cost me just a little time.πŸ™‚

    But you learned something?

  • Steve Jones - SSC Editor - Tuesday, February 28, 2017 9:34 AM

    George Vobr - Tuesday, February 28, 2017 9:29 AM

    Thanks Steve for this question, yes I had a "Fun with Time", but it cost me just a little time.πŸ™‚

    But you learned something?

    Yes, with the data type TIME I still did not work. And finally, I repeated the datetime functions, thanks.

  • Truly a fun question.  Thanks Steve.

Viewing 9 posts - 1 through 8 (of 8 total)

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