Click here to Skip to main content
15,889,595 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I have two time fields in access table.
I need coding to find the difference between
the two times.
Posted
Updated 29-Sep-15 2:15am
v2
Comments
Leo Chapiro 29-Sep-15 8:16am    
What have you tried, where are you stuck?

A proper MS Access query should look like:
SQL
SELECT DateDiff ("d", t1.FirstDateTimeField, t1.SecondDateTimeField)
FROM table1 AS t1


See:
DateDiff Function[^]
MS Access: DateDiff Function[^]

You can achieve the same by using vb.net DateFiff function[^], but i do not recommend to use it. Rather than it, use TimeSpan[^]:

VB
Dim departure As DateTime = #06/12/2010 6:32PM#
Dim arrival As DateTime = #06/13/2010 10:47PM#
Dim travelTime As TimeSpan = arrival - departure
Console.WriteLine("{0} - {1} = {2}", arrival, departure, travelTime)
' The example displays the following output:
'       6/13/2010 10:47:00 PM - 6/12/2010 6:32:00 PM = 1.04:15:00
 
Share this answer
 
Comments
CHill60 30-Sep-15 10:22am    
5'd for covering all the bases
Maciej Los 30-Sep-15 10:24am    
Thank you, Caroline.
 
Share this answer
 
Comments
F-ES Sitecore 29-Sep-15 8:31am    
Using TimeSpan will be the better .net solution.
Read you time fields to two variables, startTime and endTime.
Then:
VB
Dim span As TimeSpan
span = endTime.Subtract(startTime)
 
Share this answer
 
SELECT DATEDIFF(day,'2014-06-05','2019-09-05') AS differencedate 
 
Share this answer
 
Comments
Maciej Los 29-Sep-15 12:52pm    
My vote of 1. You did provide solution for MS SQL Server instead of MS Access.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900