Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2009
    Posts
    46

    Unanswered: Convert Time HH:MM into minuts in sqlserver

    Hi,

    I have a Start time and endtime with below format:
    Starttime=09:30
    endtime=06:30

    I want to convert starttime and in time into minuts.

    please suggest me how to convert it?

    Thanks

    Prasad

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    How are these stored? Are they DATETIME, CHAR, or another data type?

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Jun 2009
    Posts
    46
    time fields are varchar datatype.

  4. #4
    Join Date
    Dec 2008
    Posts
    135
    i am not sure is this correct try this
    declare @starttime varchar(32)
    select @starttime = '9:30'
    select datediff(mi,0,cast(@starttime as datetime))

  5. #5
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    The MinuteOfDay expression is all you really care about, the rest of this code is just to prove that it works correctly.
    Code:
    SELECT t, 60 * LEFT(t, 2) + RIGHT(t, 2) AS minuteOfDay
       FROM (SELECT RIGHT(CONVERT(CHAR(3), zh.number), 2) 
    +    ':' + RIGHT(CONVERT(CHAR(3), zm.number), 2) AS t
          FROM master.dbo.spt_values AS zh
          CROSS JOIN master.dbo.spt_values AS zm
          WHERE  'P' = zh.type
             AND 'P' = zm.type
             AND zh.number BETWEEN 100 and 123
             AND zm.number BETWEEN 100 and 159) AS h
       ORDER BY t
    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

Posting Permissions

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