Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2007
    Posts
    212

    Unanswered: How to Get Time Portion From DateTime Field

    Hi,

    does any one know how to extract just the time part of a datetime field and convert into seconds?

    Thanks

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT DATEDIFF(S
                   ,GETDATE()
                   ,DATEADD(D,DATEDIFF(D,0,GETDATE()),0)) 
             AS seconds_since_midnight_today
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I created and used @d, you can use whatever you like.
    Code:
    DECLARE @d		DATETIME
    SET @d = GetDate()
    SELECT DATEDIFF(s, DateAdd(d, DateDiff(d, 0, @d), 0), @d), @d
    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  4. #4
    Join Date
    Aug 2010
    Location
    Tampa, FL
    Posts
    1
    I have same problem too. Thank you for the info. It really helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •