473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Datadiff

kirubagari
158 100+
Hi ,

I would like to convert the datadiff to hours,minutes and second and total up batch time and build time in different column . Can expert show how this can be done in below query?

Expand|Select|Wrap|Line Numbers
  1. SELECT file_name, org_rcvd_dts,
  2.         DateDiff(hh, bld_start_dts, bld_end_dts)  AS Batch_time, 
  3.         DateDiff(hh, cnv_start_dts, cnv_end_dts)   AS Build_time 
  4. FROM   build_log(nolock) 
  5. WHERE  status <> 'DoNotRerun' 
  6.        AND dist_id = 2 
  7.        AND build_type = 'Full' 
  8. ORDER  BY cnv_start_dts 
Dec 7 '16 #1
3 1416
PhilOfWalton
1,430 Expert 1GB
Basically you need to get the DateDiff in seconds, not hours as in your code. Then convert the seconds to hours, minutes and seconds.

So Try

Expand|Select|Wrap|Line Numbers
  1. Dim Hrs as Integer
  2. Dim Mins as Integer
  3. Dim Secs as Integer
  4.  
  5. SELECT file_name, org_rcvd_dts,
  6.         DateDiff("s", bld_start_dts, bld_end_dts)  AS Batch_time, 
  7.         DateDiff("s", cnv_start_dts, cnv_end_dts)   AS Build_time 
  8. FROM   build_log(nolock) 
  9. WHERE  status <> 'DoNotRerun' 
  10.        AND dist_id = 2 
  11.        AND build_type = 'Full' 
  12. ORDER  BY cnv_start_dts 
  13.  
  14. Hrs = BatchTime \ 3600   ' Note the backslash returns only the whole number of hours
  15. Mins = (BatchTime - (Hrs * 3600)) \60
  16. Sesc - BatchTime - (Hrs * 3600) - (Mins * 60)
  17.  
Note that with the DateDiff function, the time unit is a string and needs to be surrounded with quotes. I doubt that your function with hh and no quotes would have worked.

Phil
Dec 7 '16 #2
kirubagari
158 100+
Hi Phil,

Thank you. Im using the SQL server and the query is not detected as SQL query.
Expand|Select|Wrap|Line Numbers
  1. Declare @num_hours  Integer
  2. Declare @num_minute as Integer
  3. Declare @num_sec as Integer
  4.  
  5.  
  6. SELECT file_name, org_rcvd_dts,
  7.         DateDiff("s", bld_start_dts, bld_end_dts)  AS Batch_time, 
  8.         DateDiff("s", cnv_start_dts, cnv_end_dts)   AS Build_time 
  9. FROM   build_log(nolock) 
  10. WHERE  status <> 'DoNotRerun' 
  11.        AND dist_id = 2 
  12.        AND build_type = 'Full' 
  13. ORDER  BY cnv_start_dts 
  14.  
Where should i declare the conversation part
Dec 7 '16 #3
PhilOfWalton
1,430 Expert 1GB
Whoops, sorry. I was thinking it was Access VBA. Don't know anything about SQL server, so I can't help anymore. I think, providing you can get your query to return the seconds, the conversion to hours, minutes & seconds should work

Again, apologies.

Phil
Dec 7 '16 #4

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

Similar topics

1
by: Arargorn | last post by:
I am trying to create a database that involves time calculation (elapsed time). I have set up several tables and one is for "Time Card" entry. I cannot figure out how to calculate the elapsed time...
5
by: Alec | last post by:
Hi All, I've asked about this before, and people were very helpful, and I have used the advise quite a bit, however I have run into a spot of trouble... I have a form that the users uses to...
3
by: MMFBprez | last post by:
I am trying to compute storage charges by getting the number of months between dates and multiplying it by a rate. I cannot get a correct number of months if the date is greater than a year ago. ...
7
by: guy | last post by:
Has anyone any experience of the conversion wizard for VB6 to VB2005? if so how good is it? also how does it handle database related conversions i.e is ADO converted to ADO.NET etc. the project...
0
by: Babak | last post by:
Hi I am trying to find a way to fliter a DefaultView to filter Time Stamp DataTime For example I want to know if there is any row that have Time stmp greater then Today . The Datadiff function...
4
Zerin
by: Zerin | last post by:
To all, Best regards.I submitted this problem about auto purge a database many days ago but there's no reply till now.If anyone has any solution,please reply as soon as possible. Is aouto...
3
by: rn5a | last post by:
In my local computer, date has been set in this format - dd/MM/yyyy. When I insert records in a MS-Access DB table using ASP.NET, then the records get inserted in the Access DB table exactly in the...
6
by: aapulido | last post by:
I'm creating a timekeeping database, and i need help on how to compute the Hoursworked based on In and Out. Please help me on this
4
by: Brita | last post by:
You guys have been life savers for me, and I appreciate your help so much. I am trying to check the difference in days between two submitted requests. DateFormat df =...
4
by: brendanmcdonagh | last post by:
Hi all, I ve discovered the power of php/mysql/html in last few days whilst putting together an online app to enable the staff of a friends company to log on and enter their current location and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...

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.