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

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
Stef MerlijnDeveloperAsked:
Who is Participating?
 
wimmeyvaertCommented:
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
 
ziolkoCommented:
this comes from MSSQL try maybr it will work on Access
DATEDIFF(mi, <startdate>, <enddate>)

ziolko.
0
 
mikelittlewoodCommented:
Assuming MS Access has the function DATEDIFF

SELECT DateDiff( mi, <STARTDATE>, <ENDDATE>) AS MinutesBetween
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 
ziolkoCommented:
hi, mike
looks like youre few seconds later:)
ziolko.
0
 
wimmeyvaertCommented:
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
 
wimmeyvaertCommented:
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
 
mikelittlewoodCommented:
Yeah looks like we posted seconds apart Ziolko   :o)
0
 
Stef MerlijnDeveloperAuthor Commented:
Thank you both very much for the solution.
I never knew that you can use the "as"-value within the statement.

Regards,
Stef
0
 
wimmeyvaertCommented:
Glad to be of some help.
And thanks for the points and the grade.

Best regards,

The Mayor.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.