We help IT Professionals succeed at work.

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

on
Medium Priority
675 Views
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
Comment
Watch Question

## View Solutions Only

software developer
CERTIFIED EXPERT
Top Expert 2008
Commented:
this comes from MSSQL try maybr it will work on Access
DATEDIFF(mi, <startdate>, <enddate>)

ziolko.

Not the solution you were looking for? Getting a personalized solution is easy.

Engineer

Commented:
Assuming MS Access has the function DATEDIFF

SELECT DateDiff( mi, <STARTDATE>, <ENDDATE>) AS MinutesBetween
software developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
hi, mike
looks like youre few seconds later:)
ziolko.

Commented:
I guess it should be :
SELECT DateDiff( "n", <STARTDATE>, <ENDDATE>) AS MinutesBetween

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

The Mayor

Commented:
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

Engineer

Commented:
Yeah looks like we posted seconds apart Ziolko   :o)
Commented:
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.
Developer

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

Regards,
Stef

Commented:
Glad to be of some help.
And thanks for the points and the grade.

Best regards,

The Mayor.
##### Thanks for using Experts Exchange.

• View three pieces of content (articles, solutions, posts, and videos)
• Ask the experts questions (counted toward content limit)
• Customize your dashboard and profile