Solved

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

Posted on 2006-10-19
9
595 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
  • 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
 
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now