Time calculation from Date & Time

夙愿已清 提交于 2021-02-05 08:14:28

问题


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.

(Added for Gustav)


回答1:


Something like:

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

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


来源:https://stackoverflow.com/questions/61082505/time-calculation-from-date-time

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!