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: -
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
-
but it is not working.
Others solutions?
5 2934
Is there a key that identifies the event? Like an EVENTID or something? Or do you have a table per event?
~~ CK
yes,i have an ID column called INDEX (unique value) for each row.
Would something like this work, or must the first "table" in the FROM clause be a table, not a query?: -
SELECT DateDiff(maxValue.DATE, minValue.DATE) AS 'Difference'
-
FROM (select min(INDEX) AS minimus, max(INDEX) AS maximus
-
FROM mytable) AS range,
-
mytable AS minValue,
-
mytable AS maxValue
-
WHERE (range.minimus = minValue.INDEX)
-
AND (range.maximus = maxValue.INDEX)
-
Luck!
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
-
<body>
-
<input type="time" step="1" id="startTimeInput" name="start_time" value=""><br> <!-- write as like 02:31:55 -->
-
<input type="time" step="1" id="endTimeInput" name="end_time" value=""><br>
-
<button id="calcBtn">Seconds</button><br>
-
<div id="result"></div>
-
<script type="text/javascript" src="js/jquery.js"></script>
-
<script type="text/javascript">
-
document.getElementById('calcBtn').onclick = function(){
-
var startTime = document.getElementById('startTimeInput').value;
-
var endTime = document.getElementById('endTimeInput').value;
-
var result = getDeltaSeconds(startTime, endTime);
-
document.getElementById('result').innerHTML = result + ' sec';
-
}
-
function getDeltaSeconds(startTime, endTime){
-
var startTimeSeconds = getSeconds(startTime);
-
var endTimeSeconds = getSeconds(endTime);
-
return endTimeSeconds - startTimeSeconds;
-
}
-
function getSeconds(timeString){
-
var parts = timeString.split(' ');
-
var time = parts[0];
-
var ampm = parts[1];
-
var timeParts = time.split(':');
-
var seconds = Number(timeParts[2]) + Number(timeParts[1]*60) + Number(timeParts[0]*60*60);
-
return ampm == 'AM' ? seconds : seconds + 12*60*60;
-
}
-
</script>
-
</body>
-
-
Sign in to post your reply or Sign up for a free account.
Similar topics
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)...
|
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)
{
|
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...
|
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
|
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...
|
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...
|
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...
|
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.
...
|
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:
...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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: 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...
|
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...
|
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,...
| |