?
Solved

Get the logged in time

Posted on 2000-05-10
8
Medium Priority
?
124 Views
Last Modified: 2010-05-02
I have two variables containing the time.

Both are strings:

txtLoginTime    ' 08:54:11 AM
txtLogoutTime   ' 06:03:55 PM

Guess what I want :)  I want to know how long they were logged in.

This should be an easy one.

t
0
Comment
Question by:prosit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 200 total points
ID: 2796124
abs(datediff("s","08:54:11","06:03:55")) will return 10216 which is the number of seconds between the two times. You can then work out minutes and hours easily.

Hope this helps.
0
 
LVL 12

Expert Comment

by:pjknibbs
ID: 2796130
Use the CDate function to convert your times to a Variant of type Date, then subtract them.

e.g. CDate(txtLogoutTime) - CDate(txtLoginTime)

The result will be another Variant:Date containing the difference between the two times...I think!!
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 2796150
pjknibbs, subtracting two date values in this way will give you a decimal value representing the number of days between them:

?(cdate("08:54:11") - cdate("06:03:55") )
returns  0.118240740740741
which mulitplied by 60 * 60 * 24 to get the seconds is 10216 as per my previous example.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:prosit
ID: 2796168
It will always be the same day.

(they have to go home at some point :)

t
0
 
LVL 2

Author Comment

by:prosit
ID: 2796204
U got it, works great!

t
0
 
LVL 12

Expert Comment

by:pjknibbs
ID: 2796297
TimCottee: You hadn't posted your answer when I wrote mine--check the times out! I wasn't attempting to steal the question out from under you, if that's what you're implying.
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 2796516
I wasn't trying to imply that you were stealing pjknibbs, just clarifying your method which though different would have worked perfectly well given that you have to multiply up to get the correct answer. I apologise for any implication, it certainly wasn't intended.
0
 
LVL 12

Expert Comment

by:pjknibbs
ID: 2797077
TimCottee: Sorry I was a bit snappy--3 o'clock in the afternoon in a steaming hot office syndrome. <G>
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month10 days, 17 hours left to enroll

770 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