473,749 Members | 2,463 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

converting minutes to hh:mm:ss in sql

1 New Member
I have query like this:
Expand|Select|Wrap|Line Numbers
  1. select SUM(DATEDIFF(MI,t.Paydate,t.DelDate)) as sum_min,
  2.        AVG( CONVERT(NUMERIC(18,2), DATEDIFF(MI,t.Paydate,t.DelDate) ) ) as avg_min
  3. from Transaction_tbl t where t.transactID in(24,25)
  4. group by t.vtid
I am getting out put like this:
Expand|Select|Wrap|Line Numbers
  1. sum_min     avg_min
  2. ----------- ---------------------------------------
  3. 26          26.000000
  4. 7           7.000000
now am getting sum_min out put in minutes,insted of geting out put in minutes i want to show in HH:mm:ss,Expect ed out put like this:
Expand|Select|Wrap|Line Numbers
  1. sum_min     avg_min
  2. ----------- ---------------------------------------
  3. 00:26:00          26.000000
  4. 00:07:00           7.000000
SO i tryed query like this:
Expand|Select|Wrap|Line Numbers
  1. SELECT convert(varchar(10),sum(DATEDIFF(hour,t.Paydate,t.DelDate)))+':' 
  2.       +convert(varchar(10),sum(DATEDIFF(minute,t.Paydate,t.DelDate)% 60)) + ':' 
  3.       +convert(varchar(10),sum(DATEDIFF(SECOND,t.Paydate,t.DelDate)% 60)) 
  4.        AS ' HH:MM:SS'
  5. FROM Transaction_tbl t 
  6.  
  7. WHERE t.transactID in(24,25) group by vtid
..so am getting out put like this:
Expand|Select|Wrap|Line Numbers
  1.  HH:MM:SS
  2. --------------------------------
  3. 1:26:36
  4. 1:7:25
showing 1 hr extra. how i can get proper answer
Jul 21 '13 #1
1 3950
Rabbit
12,516 Recognized Expert Moderator MVP
I don't see what this has to do with .net. Let us know what SQL database server you're using and we can move it to the correct forum.

Please use code tags when posting code or formatted data.

That's because the datediff function rounds up. If you want it to be accurate down to the second, you need to get the difference in seconds for hours and minutes and use integer division.
Jul 21 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
18586
by: renee_ld | last post by:
In a query I used the function datediff to calculate the number of minutes between two time periods on a given day. This function returned the number of minutes as a long integer data type. I then formatted the summed number in my report footers using: =Format(Int(Sum()/60),"00") & ":" & Format(( Mod 60),"00")
1
1539
by: Hans [DiaGraphIT] | last post by:
Hi! I have a logical problem. How can I convert 2 textboxvalues,(one for hours and one for minutes) to a common value type of float or double. I wish to save this new value in a database Any help appreciates --- < Hans > ---
5
16892
by: Masahiro Ito | last post by:
I have column of data that have elapsed time in minutes. For example: 1:15 1:47 23:12 I like to be able to use sql server to do simple math functions. Does anyone have a simple function/formula that will convert into a decimal minutes form?
6
26559
by: Harlin Seritt | last post by:
I would like to take milliseconds and convert it to a more human-readable format like: 4 days 20 hours 10 minutes 35 seconds Is there something in the time module that can do this? I havent been able to find anything that would do it. Thanks,
2
10836
by: Harlin Seritt | last post by:
How can I take a time given in milliseconds (I am doing this for an uptime script) and convert it to human-friendly time i.e. "4 days, 2 hours, 25 minutes, 10 seonds."? Is there a function from the time module that can do this? Thanks, Harlin Seritt
3
1762
by: si_owen | last post by:
Hi folks, I am returning a value from a db table, which is the number of mins. I need to convert this to hrs mins which I have done using the following code, and also displayed it in my grid: Dim ts As TimeSpan = TimeSpan.FromMinutes(balance) tempItem.Cells(8).Text = (ts.Hours & ":" & ts.Minutes) However I have a problem with the minutes, 8:04 is currently displayed
3
1663
by: Sean Farrow | last post by:
Hi: I have the folling code: def parseTime(self, time): minutes =int(float(time)/60) seconds =int(float(time)-minutes*60) minutes =str(minutes) seconds =str(minutes) the statements that convert the minutes and seconds variables str(minutes) and str(seconds) don't seem to be working. Any idea why?
2
12348
by: mar10 | last post by:
i have TIME WORKED stored as minutes - I'd like to convert this to days,hours,minutes. I'm currently converting to hours and minutes but have not had success adding the days portion to the formula below. Any direction is greatly appreciated. thanks
2
4769
by: phanicrn | last post by:
Hi Everyone I Have column in sql server databas as "HHMMSS" and data as and i am doing a substring to get values for hours and minutes. since my calculations based on hour interval and 30 minutes interval for ex: Now i want to show all the transaction done b/w 6 to 7 am or pn. and for 30 minutes interval i have get the calculation as transactions done b/w 6:00 to 6:30 and 6:30 to 7:00 either it's am or pm. now how i can write my...
5
8509
by: neelsfer | last post by:
I need to add a stopwatch (textbox type) - does not need to be fancy, to a form showing hhmmss, start/stop and reset buttons. Anybody with code for it?
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9566
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9388
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6800
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.