Solved

How to calculate number of minutes between two DateTime in a query?

Posted on 2006-10-19
9
629 Views
Last Modified: 2010-04-05
Hi,

In Delphi I can calculate the number of minutes between two dates by using the function:
MinutesBetweenEx(StartDateTime, EndDateTime);

Is there a way to do this within a query?
I'm using a MS Access database.

Regards,
Stef
0
Comment
Question by:Delphiwizard
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 21

Assisted Solution

by:ziolko
ziolko earned 200 total points
ID: 17764422
this comes from MSSQL try maybr it will work on Access
DATEDIFF(mi, <startdate>, <enddate>)

ziolko.
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 17764424
Assuming MS Access has the function DATEDIFF

SELECT DateDiff( mi, <STARTDATE>, <ENDDATE>) AS MinutesBetween
0
 
LVL 21

Expert Comment

by:ziolko
ID: 17764439
hi, mike
looks like youre few seconds later:)
ziolko.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:wimmeyvaert
ID: 17764581
I guess it should be :
SELECT DateDiff( "n", <STARTDATE>, <ENDDATE>) AS MinutesBetween

instead of

SELECT DateDiff( mi, <STARTDATE>, <ENDDATE>) AS MinutesBetween

Best regrads,

The Mayor
0
 
LVL 6

Expert Comment

by:wimmeyvaert
ID: 17764590
And use :

For Hours    : SELECT DateDiff( "h", <STARTDATE>, <ENDDATE>) AS HoursBetween
For Minutes : SELECT DateDiff( "n", <STARTDATE>, <ENDDATE>) AS MinutesBetween
For seconds : SELECT DateDiff( "s", <STARTDATE>, <ENDDATE>) AS SecondsBetween

See http://www.access-programmers.co.uk/forums/showthread.php?t=14680

0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 17764628
Yeah looks like we posted seconds apart Ziolko   :o)
0
 
LVL 6

Accepted Solution

by:
wimmeyvaert earned 300 total points
ID: 17764685
Little Extention to what you were asking :

SELECT FromDate, ToDate,
       DATEDIFF( "s", FromDate, ToDate) as TotalSeconds,
       INT(TotalSeconds / 3600) as Hours,
       INT( ((TotalSeconds / 3600) - Hours) *60 ) as Minutes,
       INT( ((((TotalSeconds / 3600) - Hours) *60) - Minutes) *60 ) as Seconds
from YourTableNameHere

Best regards,

The Mayor.
0
 

Author Comment

by:Delphiwizard
ID: 17793824
Thank you both very much for the solution.
I never knew that you can use the "as"-value within the statement.

Regards,
Stef
0
 
LVL 6

Expert Comment

by:wimmeyvaert
ID: 17793878
Glad to be of some help.
And thanks for the points and the grade.

Best regards,

The Mayor.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question