Calculating Time Difference

Posted on 2005-04-09
Last Modified: 2013-12-18
Hi everyone,

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

Cheers all...
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


    source is notesuidocument


    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 ?

    Thanks in advance.
    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

    Author Comment

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

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    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.
    Article by: Rob
    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 ( 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…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now