• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 130
  • Last Modified:

Get the logged in time

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
prosit
Asked:
prosit
  • 3
  • 3
  • 2
1 Solution
 
TimCotteeHead of Software ServicesCommented:
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
 
pjknibbsCommented:
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
 
TimCotteeHead of Software ServicesCommented:
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
prositAuthor Commented:
It will always be the same day.

(they have to go home at some point :)

t
0
 
prositAuthor Commented:
U got it, works great!

t
0
 
pjknibbsCommented:
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
 
TimCotteeHead of Software ServicesCommented:
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
 
pjknibbsCommented:
TimCottee: Sorry I was a bit snappy--3 o'clock in the afternoon in a steaming hot office syndrome. <G>
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now