Solved

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

Posted on 2006-10-19
9
624 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
Independent Software Vendors: 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

734 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