Solved

How to calculate time difference using Lotus Script

Posted on 2001-06-25
17
1,947 Views
Last Modified: 2013-12-18
Hi,
  I need to write a time sheet entry screen for my user.
On the form, I have the date of entry (field name: date), time start (field name: Startwork), Time end (field name:Endwork).
 
   Can anybody advise, how to calculate the time difference. I have the field timespent. To calculate the difference between Startwork and Endwork.

   Please advise.
   Thanks in advance
   CT2000
0
Comment
Question by:CT2000
  • 7
  • 6
  • 2
  • +1
17 Comments
 
LVL 8

Expert Comment

by:Jean Marie Geeraerts
Comment Utility
I suppose all fields are date/time fields where you only display the time as hh:mm.

In this case put the following formula in your TimeSpent Date/time field :
Temp:=@if(Endwork="" | Startwork=""; ""; Endwork-Startwork);
@if(Temp="";""; @time(@integer(Temp/3600);(Temp-(@integer(Temp/3600))*3600)/60;0))

The first line will calculate the value in seconds.
The second line will convert the result back to a time value so it will display as hh:mm in your field.
0
 
LVL 13

Expert Comment

by:CRAK
Comment Utility
I tested following formula in a button, assuming only the two time-fields were relevant. D1 and D2 are my NotesDateTime fields (time only; hours, minutes and seconds):

Sub Click(Source As Button)
     Dim WS As New NotesUIWorkspace
     Dim UIDoc As NotesUIDocument
     Dim Dt1 As NotesDateTime
     Dim Dt2 As NotesDateTime
     Dim Dt3 As NotesDateTime
     
     Set UIDoc = WS.CurrentDocument
     Set Dt1 = New NotesDateTime(UIDoc.FieldGetText("D1"))
     Set Dt2 = New NotesDateTime(UIDoc.FieldGetText("D2"))
     
     Set Dt3 = Dt2
     Call Dt3.AdjustHour(-Hour(Dt1.LsLocalTime))
     Call Dt3.AdjustMinute(-Minute(Dt1.LsLocalTime))
     Call Dt3.AdjustSecond(-Second(Dt1.LsLocalTime))
     Messagebox Dt3.LsLocalTime
End Sub
0
 
LVL 8

Expert Comment

by:Jean Marie Geeraerts
Comment Utility
Why so complicated CRAK ? It can be done with a simple calculated field with the formula as stated in my comment above ;-)
Hey aren't you getting close to the TOP-15?
0
 
LVL 13

Expert Comment

by:CRAK
Comment Utility
I would not have chosen lotusscript to solve this one myself, jerrith. I'd rather keep it simple and @-coded, but the question was to use Lotusscript (see subject header).
Quite a popular topic this week: date/time handling, isn't it?
0
 

Author Comment

by:CT2000
Comment Utility
Hi,
   Below is the model answer:

Sub Click(Source As Button)
     Dim x As New Notesuiworkspace
     Dim u As notesuidocument
     Set u = x.currentdocument
     Dim timetaken As  Double
     Dim Roundedtime As Double
     Dim texttime As String
     Dim Starttime  As NotesDatetime
     Dim EndTime As NotesDatetime
     Set StartTime = New NotesDatetime(u.fieldgetText("StartWork"))
     Set EndTime = New NotesDatetime (u.fieldgetText("EndWork"))
     timetaken =  ( endTime.TimeDifference (Starttime))  / 3600  
'     texttime =  @Round(timetaken; 1)
     
     Call u.fieldsettext("TimeSpent", texttime)
     Messagebox timetaken, , "timetaken"
End Sub

  One shortcoming is when the "timetaken" has been calculated it is having too many decimal places. I try to use the formula @Round. But it does not work! (     texttime =  @Round(timetaken; 1)) I need to round it to two decimal places.
    Please advise
    Thanks in advance.
    CT2000
0
 
LVL 13

Expert Comment

by:CRAK
Comment Utility
"When using Lotusscripot, you can't use @-functions (unless you use Evaluate). Try "Round" (without "@") instead.
0
 
LVL 8

Expert Comment

by:Jean Marie Geeraerts
Comment Utility
CRAK,
Yes, it does seem to be a popular subject this week.
I just ignored the question header and suggested what I thought was the best/simplest answer.
Anyway if CT2000 insists on using LotusScript he can use your code. As you said, I too would prefer to use @formula's in this case.

CT, to convert your value to a correct string :
texttime = format$(cint(timeTaken/3600), "00") + ":"  + format$((timeTaken-(cint(timeTaken/3600)*3600)))/60, "00")

You cannot use @formula's in lotusscript, unless you pass them to the script function "evaluate".
0
 
LVL 8

Expert Comment

by:Jean Marie Geeraerts
Comment Utility
If you need to display time spent as a digital value, it's even simpler : texttime=format$(timetaken, "0.00")
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 13

Expert Comment

by:CRAK
Comment Utility
What a team!
By the way jerrith: I only have 4460 pt in the Lotus Notes area. I only started Oct last year. Back then approx 5500 was nearly enough for a top 10 entry, but whenever I am to busy at work, you guys continue increasing the gap :-((
It that T-shirt worth it?
0
 
LVL 8

Expert Comment

by:Jean Marie Geeraerts
Comment Utility
Yes, it's good quality. You have to be patient, though. I still haven't gotten my second one. Come to think of it, I think I'm gonna send the guys at EE a little reminder about that ;-)
I know what you mean, I've been a bit busy at work lately and before I know it Sloeber has overtaken me with some easy questions :-(
And to think that all he knows about the web he learned from me! Hihi
0
 
LVL 1

Expert Comment

by:Moondancer
Comment Utility
It's time to clean up this topic area and that means taking care of this question. Your options at this point are:

1. Award points to the Expert who provided an answer, or who helped you most. Do this by clicking on the "Accept Comment as Answer" button that lies above and to the right of the appropriate expert's name.

2. PAQ the question because the information might be useful to others, but was not useful to you. To use this option, you must state why the question is no longer useful to you, and the experts need to let me know if they feel that you're being unfair.

3.  Ask Community Support to help split points between participating experts.  Just comment here with details.

4.  Delete the question because it is of no value to you or to anyone else.  To use this option, you must state why the question is no longer useful to you, and the experts need to let me know if they feel that you're being unfair.

If you elect for option 2, 3 or 4, just post comment with details here and I'll take it from there.  We also request that you review any other open questions you might have and update/close them.  Display all your question history from your Member Profile to view details.

PLEASE DO NOT AWARD THE POINTS TO ME.

____________________________________________



Hi Experts:

In the event that the Asker does not respond, I would very much appreciate your opinions as to which Expert ought to receive points (if any) as a result of this question.  Likewise, you can also suggest that I PAQ or delete the question.

Experts, please do not add further "answer" information to this question.  I will be back in about one week to finalize this question.

Thank you everyone.

Moondancer :)
Community Support Moderator @ Experts Exchange

P.S.  REGARDING POINTS, Guidelines and more:  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp  
0
 
LVL 8

Expert Comment

by:Jean Marie Geeraerts
Comment Utility
In my opinion it would be fair to split points between CRAK and myself. Since we both provided a valid answer to the question.
0
 
LVL 13

Accepted Solution

by:
CRAK earned 10 total points
Comment Utility
I agree.
0
 

Author Comment

by:CT2000
Comment Utility
Hi Expert Exchange team,
   Could you please split the point between the two experts
0
 
LVL 1

Expert Comment

by:Moondancer
Comment Utility
Hi, CT2000.

Let's see what the experts here say in that regard.  You have already chose a comment here and accepted it as the answer and graded to close it with a "C".  Few (if any) experts appreciate a "C" grade, and this question total was only 10 points.  "Easy" questions typically begin at a point value of 50.  

Will listen further when I can in this regard.

Moondancer
Community Support Moderator @ Experts Exchange
0
 
LVL 8

Expert Comment

by:Jean Marie Geeraerts
Comment Utility
Yep, people giving C's get notes in my little black book ;-)

I'm not all that keen on putting a lot of time and effort in questions asked by somebody that frequently just gives a C, even though an expert has spent a reasonable amount of time to try to help.

I think it's a matter of principle. I nearly always give an A-grade, just to show my appreciation for the help offered. If I give a B, that will mean the answer I got was very lame and there was no better alternative. I never give a C myself. But I can understand that sometimes an expert doesnt deserve more than a C, however in this particular question I don't really think any of us deserved a C grade, do you?

Please don't take offense, this is just my opinion.
0
 
LVL 13

Expert Comment

by:CRAK
Comment Utility
Are you sure?
I'd rather have a "C" on a 100pt question than an "A" on a 10pt one.... Get's me those T-shirts a bit faster!  ;-))

It's the challenge for me.... helping others and trying to do so better/faster than others. As long as things move towards a solution and not bleed to death for some reason!

After have done a real lot of effort, a "C" hurts a bit, but sometimes problems cannot be solved 100%. Would an "A" be fair in such case?
Solution: raise point first, then gade "C"....
Just gidding!

* signing off *
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

12 Experts available now in Live!

Get 1:1 Help Now