MSSQL help using date function - to get peak range of ATIME and EndTime

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dragrid
    New Member
    • Jan 2009
    • 29

    MSSQL help using date function - to get peak range of ATIME and EndTime

    Hi anyone - appreciate any help

    I would like to get * one column * with that min of the day instead of hr and min separately
    So the first line for example 18:50 pm would be the 1130 min of the day
    And if it was 6:50 am would be 410 min of a day
    What is the best function I can use in my select statement to get this and be able to group by it ?

    select datepart(yyyy,A TIME)as yr, datepart(mm,ATI ME)as mth, datepart(dd,ATI ME)as daday
    ,datepart(hh,AT IME)as hr,datepart(mi, ATIME)as strtmin
    From table
    Where (ATIME >= '2010-02-01 00:00:00') and (ATIME <= '2010-02-28 23:59:59')
    and datename(weekda y,ATIME) in ( 'Friday','Satur day','Sunday')
    group by datepart(yyyy,A TIME),datepart( mm,ATIME),datep art(dd,ATIME),
    datepart(hh,ATI ME),datepart(mi ,ATIME)
    order by strtmin desc

    yr mm dd hr mi
    2010 2 13 18 50
    2010 2 6 18 50
    2010 2 26 14 50
    2010 2 28 9 50
    2010 2 14 20 49
    2010 2 20 16 49
    2010 2 12 1 49
    2010 2 28 19 49
    2010 2 5 1 49

    My columns looks like this
    ATIME EndTIME

    2010-02-01 00:00:00.000 2010-02-01 00:02:30.000
    2010-02-01 00:00:00.000 2010-02-01 00:00:26.000
    2010-02-01 00:00:02.000 2010-02-01 00:55:53.000
    2010-02-01 00:00:02.000 2010-02-01 00:16:35.000

    Thanks in advance
  • Delerna
    Recognized Expert Top Contributor
    • Jan 2008
    • 1134

    #2
    Don't know it there is a function (probably) but it is an easy math problem

    SELECT datepart(hh,ATI ME) * 60 + datepart(mi,ATI ME) as MinuteOfTheDay
    FROM........

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      Are you talking about getting the elapsed time in minutes since midnight? Use DATEDIFF().

      Happy Coding!!!

      ~~ CK

      Comment

      Working...