Solved

Calculating Time Difference

Posted on 2005-04-09
321 Views
Hi everyone,

I have Time1 and Time2, how can I let Lotus Script to calculate the time difference automaticaly, like Time2 - Time1 ?

Cheers all...
0
Question by:Faraj1969

LVL 14

Accepted Solution

Set firstTime = New NotesDateTime(source.FieldGetText("Time1"))
Set secondTime = New NotesDateTime(source.FieldGetText("Time2"))

If secondtime.TimeDifference(firsttime) > 0 Then

nodayssecs=secondtime.TimeDifference(firsttime)
nodays=nodayssecs/86400

source is notesuidocument

Partha
0

Author Comment

Thanks Partha,

Set Tfrom      = New NotesDateTime( UIDoc.FieldGetText( "Ndf_1" ) )       ' From Time
Set Tto      = New NotesDateTime( UIDoc.FieldGetText( "Ndt_1" ) )       ' To Time

Call UIDoc.FieldSetText( "Ndh_1", Trim( Cstr( Tto.TimeDifference( Tfrom ) / 86400 ) ) )

I entered 17:00 for Tfrom field and 19:00 for Tto field, the result was 8.33333333333333E-02
Ndh_1 is DateTime computed field.  The code worked but not the result I was looking for.

Any remedy ?

0

LVL 31

Assisted Solution

Tto.TimeDifference( Tfrom ) / 86400 returns the fraction of a day between the two.  It is returning exactly what you asked for -- but not in the way you want it to.

The actual difference is 2 hours, or 2*60=120 minutes, or 120*60=7200 seconds, which is what TimeDifference is actually retruning.  But, when you divide by a days' worth (86400) of seconds, you get 7200/86400, same as 2/24 hours, which is 8.33333333333333E -- otherwise known as as 0.083333333333333.  Absolutely accurate -- try dividing 2 by 24.

Partha was ASSUMING you wanted the difference in # of days.  WHat you really want is seconds, minutes, or hours. Or maybe you want a time format of hh:mm.

To get seconds, just leave off the /86400.  To get minutes, use /60 instead of 86400.  To get hours, use /3600 instead of /86400.

To get a nice time format, use:

allSeconds = ...Tto.TimeDifference( Tfrom )
hours = allSeconds\3600
remaining = allSeconds mod 3600
minutes = remaining\60
seconds = remaining mod 60
displayDif = hours & ":" & minutes & seconds
...FieldSetText "Ndh_1" , displayDif
0

Author Comment

Thanks Qwaletee, thats what I needed, and sorry Partha, my explanation sucks at times, guess Qwaletee knows me... lol
0

Featured Post

Notes Document Link used by IBM Notes is a link file which aids in the sharing of links to documents in email and webpages. The posts describe the importance and steps to create a Lotus Notes NDL file in brief.
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…