Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Time Addition Problem

Time Addition Problem

Scheduled Pinned Locked Moved Database
tutorialmcphelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AliAmjad
    wrote on last edited by
    #1

    I am using the following code to Add up the difference of two time fields but It's not showing the correct record when the hours part increases above 24 means It shows the correct addition only if It's between 24 hours. For example WaitingTimeTotal (hh:mm:ss) ---------------- 03:18:46 03:25:06 ________ 06:43:52 which is correct but WaitingTimeTotal (hh:mm:ss) ---------------- 03:18:46 03:25:06 16:23:46 07:24:20 ________ wrong answer!!! The code i am using is

    convert(varchar,convert(DateTime, SUM(convert(real, ConfTime - EnterTime))),108)WaitingTimeTotal

    Can you please guide me. Thanks in advance !

    AliAmjad(MCP) First make it Run THEN make it Run Fast!

    modified on Thursday, January 15, 2009 1:28 AM

    W 1 Reply Last reply
    0
    • A AliAmjad

      I am using the following code to Add up the difference of two time fields but It's not showing the correct record when the hours part increases above 24 means It shows the correct addition only if It's between 24 hours. For example WaitingTimeTotal (hh:mm:ss) ---------------- 03:18:46 03:25:06 ________ 06:43:52 which is correct but WaitingTimeTotal (hh:mm:ss) ---------------- 03:18:46 03:25:06 16:23:46 07:24:20 ________ wrong answer!!! The code i am using is

      convert(varchar,convert(DateTime, SUM(convert(real, ConfTime - EnterTime))),108)WaitingTimeTotal

      Can you please guide me. Thanks in advance !

      AliAmjad(MCP) First make it Run THEN make it Run Fast!

      modified on Thursday, January 15, 2009 1:28 AM

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      If you want to have total hour amount, this could be one way. I used inline views to both generate a test data (inner one) and to ease the summary (the outer one).

      select convert(varchar(50), datepart(hour, datesum) + (datepart(day, datesum) - 1) * 24)
      + ':' + convert(varchar(50), datepart(minute, datesum))
      + ':' + convert(varchar(50), datepart(second, datesum))
      from (select SUM(convert(real, datecolumn)) as datesum
      from (select CONVERT(datetime, '03:18:46') as datecolumn
      union
      select CONVERT(datetime, '03:25:06') as datecolumn
      union
      select CONVERT(datetime, '16:23:46') as datecolumn
      union
      select CONVERT(datetime, '07:24:20') as datecolumn) alias1
      ) alias2

      Now the result is 30:31:57. Was this what you were after?

      The need to optimize rises from a bad design.My articles[^]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups