473,699 Members | 2,533 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 3887
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
18570
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
1537
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
26540
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
10834
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
1760
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
1662
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
12327
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
4766
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
8508
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
9054
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...
1
8941
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7785
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5881
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
4390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3071
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
2362
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.