473,416 Members | 1,630 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,416 software developers and data experts.

How to calculate duration using diff function

4
Hello!
I have a table in a database where there is a column called DATE (datetime type)that logs the date/time of an event.The first index of the table it represent the start date/time and the last index of the table represent the final date/time.
How can i make a query that returns the duration between the start date/time and final date/time?
i tryed to do:
Expand|Select|Wrap|Line Numbers
  1. select DateDiff(hour,select DATE from mytable where INDEX=(select min(INDEX) from mytable),select DATE from mytable where INDEX=(select max(INDEX) from mytable)) from mytable 
  2.  
but it is not working.
Others solutions?
Oct 16 '10 #1
5 2934
ck9663
2,878 Expert 2GB
Is there a key that identifies the event? Like an EVENTID or something? Or do you have a table per event?

~~ CK
Oct 18 '10 #2
Mirku
4
yes,i have an ID column called INDEX (unique value) for each row.
Oct 18 '10 #3
Oralloy
988 Expert 512MB
Would something like this work, or must the first "table" in the FROM clause be a table, not a query?:

Expand|Select|Wrap|Line Numbers
  1. SELECT DateDiff(maxValue.DATE, minValue.DATE) AS 'Difference'
  2.   FROM (select min(INDEX) AS minimus, max(INDEX) AS maximus
  3.           FROM mytable) AS range,
  4.        mytable AS minValue,
  5.        mytable AS maxValue
  6.   WHERE (range.minimus = minValue.INDEX)
  7.     AND (range.maximus = maxValue.INDEX)
  8.  
Luck!
Oct 18 '10 #4
ck9663
2,878 Expert 2GB
If it's a unique value for each row, how can you identify which dates belong to what event? Could you post some sample data of your table? If you have multiple events on that table, kindly include them...

A 10 record sample will do.

~~ CK
Oct 19 '10 #5
Expand|Select|Wrap|Line Numbers
  1. <body>
  2. <input type="time" step="1" id="startTimeInput"  name="start_time" value=""><br>     <!--   write as like       02:31:55   -->
  3. <input  type="time" step="1" id="endTimeInput"  name="end_time" value=""><br>
  4. <button id="calcBtn">Seconds</button><br>
  5. <div id="result"></div>
  6. <script type="text/javascript" src="js/jquery.js"></script>
  7. <script type="text/javascript">
  8. document.getElementById('calcBtn').onclick = function(){
  9.     var startTime = document.getElementById('startTimeInput').value;
  10.     var endTime = document.getElementById('endTimeInput').value;
  11.   var result = getDeltaSeconds(startTime, endTime);
  12.   document.getElementById('result').innerHTML = result + ' sec';
  13. }
  14. function getDeltaSeconds(startTime, endTime){
  15.     var startTimeSeconds = getSeconds(startTime);
  16.   var endTimeSeconds = getSeconds(endTime);
  17.   return endTimeSeconds - startTimeSeconds;    
  18. }
  19. function getSeconds(timeString){
  20.     var parts = timeString.split(' ');
  21.   var time = parts[0];
  22.   var ampm = parts[1];
  23.   var timeParts = time.split(':');
  24.   var seconds = Number(timeParts[2]) + Number(timeParts[1]*60) + Number(timeParts[0]*60*60);
  25.   return ampm == 'AM' ? seconds : seconds + 12*60*60;
  26. }
  27. </script>
  28. </body>
  29.  
  30.  
Oct 4 '16 #6

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

Similar topics

7
by: Jim Geissman | last post by:
Take a table, where not all the columns are populated: CREATE TABLE #T (A int, B int, C int, D int) INSERT #T (A,B) VALUES (1,2) INSERT #T (A,B) VALUES (3,4) INSERT #T (A,B) VALUES (5,6)...
8
by: Nick Li | last post by:
Hi, I am trying to writing a c program to send email using system() function call on Unix(Sun Solaris). I tried the following: #include <stdio.h> #include <stdio.h> int main(void) {
5
by: AK | last post by:
I'm writing a Windows Forms application in C++.NET. I've defined function F which takes 2 arguments a & b. I need to use the pointer of F inside another function G & I can't figure out how to do...
6
by: Programador | last post by:
I'm getting this error when running this program: Cannot calculate rate using the arguments provided Module Module1 Sub Main() Rate(360, -694.44444444444446, 244274.69178082192) End Sub
1
by: Muhammad Qasim Choudry via DotNetMonster.com | last post by:
I want to Use IRR Function in C#.Net but cant find it but when i open Vb.Net projetc under Microsoft.VisualBasic.Financial module i can find that function but i want to use it in in C# for...
12
by: Angel Tsankov | last post by:
I'm thinking about using a function tamplate to verify that an identifier is of an array type. May the following template be used for this purpose: template< typename T, int N > void...
13
by: arnuld | last post by:
this does not work, i know there is some problem in the "for loop" of "print_arr" function. i am not able to correct the weired results i am getting. i have no compile time error, it is only...
3
archulu
by: archulu | last post by:
hai this is archulu. i am new to domapi.now my problem is in my project i am taken 2 domapi datepickers. what i am want Calculate duration between two dates which i am selected in that datepicker. ...
2
myusernotyours
by: myusernotyours | last post by:
Hello everyone. I am using a C library from C++ code. The C library declares some function pointers using typedef, and then makes some variables using this function pointer as the type. Like: ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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...
0
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...
0
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...
0
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,...

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.