Lotus Notes Domino获取日期差异

时间:2013-03-27 01:54:46

标签: lotus-notes lotusscript

我使用lotusscript制作了一个代码来计算两个字段之间的时差,现在我想计算日期之间的差异。我几乎已经开始编写剧本,但我仍然对它有最低限度的了解。希望您能够帮助我。这是我为计算时差而编写的代码:

Sub UpdateDuration()
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim starttime As NotesDateTime
Dim endtime As NotesDateTime
Dim duration As Integer

Set uidoc = ws.CurrentDocument
If uidoc.FieldGetText("StartTime") = "" Then
    Exit Sub
Elseif uidoc.FieldGetText("StartTime") = "" Then
    Exit Sub        
End If
Set starttime = New NotesDateTime( uidoc.FieldGetText("StartTime") )
Set endtime = New NotesDateTime( uidoc.FieldGetText("EndTime") )
duration = endtime.TimeDifference( starttime )
Call uidoc.FieldSetText("Duration", Cstr(duration) )
Call uidoc.Refresh()
End Sub

1 个答案:

答案 0 :(得分:3)

TimeDifference返回两个NotesDateTimes之间的秒数。一天有60 * 60 * 24秒,这可以达到86400.所以只需按照上面的方式编写代码并将结果除以86400.(您可能想要更改的唯一其他内容是您的字段和变量名称,以反映您使用日期输入而不是时间的事实。)