Time calculation from Date & Time

Tags: , ,

I am trying to figure out a way where I can use MS access to convert the the following data to show the minutes spent within each column, whilst also discounting weekends from the final figure. This data is pulled from a project management software where the task is passed through each column as it goes through the relevant stage of calibration (hence the data format as shown). This table will also store the transition data for all products that go through this process.

Will this calculation need to be done prior to appending to this table or can this be done on the fly whenever the user wishes to see how long the item spent in each column? I am struggling to understand how I can get a query to check the row above to measure the difference in time. Please help.

enter image description here

(Added for Gustav) enter image description here


Something like:

    (Select Max(transitionDate) 
    From YourTable As T 
    Where T.product = YourTable.product And T.transitionDate < YourTable.transitionDate)
    - transitionDate As transitionTime

The time output will be days which you may have format, like hours and minutes:

Public Function FormatHourMinute( _
  ByVal datTime As Date, _
  Optional ByVal strSeparator As String = ":") _
  As String

' Returns count of days, hours and minutes of datTime
' converted to hours and minutes as a formatted string
' with an optional choice of time separator.
' Example:
'   datTime: #10:03# + #20:01#
'   returns: 30:04
' 2005-02-05. Cactus Data ApS, CPH.

  Dim strHour       As String
  Dim strMinute     As String
  Dim strHourMinute As String

  strHour = CStr(Fix(datTime) * 24 + Hour(datTime))
  ' Add leading zero to minute count when needed.
  strMinute = Right("0" & CStr(Minute(datTime)), 2)
  strHourMinute = strHour & strSeparator & strMinute

  FormatHourMinute = strHourMinute

End Function

Source: stackoverflow