formatting (Now() - time) to hh:mm:ss ... lost?! 
Author Message
 formatting (Now() - time) to hh:mm:ss ... lost?!

Hi

I need some help with processing time with the Now() function...

What I have going at the moment is that when a student first logs in...that
time is recorded using Now() and stored in access.  I retrieve this value
during processing of a ASP page and store it in a variable called PrevNow

I do a couple of things with this.

1.  A admin can then query for how long the student has been logged on for..

So I have something like

loggedtime = PrevNow - Now()

then I want to format this number loggedtime into something meaningfull like
hh:mm:ss...I've tried format...and some dozen variations but I can't produce
anything that looks pretty.

2. On the same vein....I would also like to be able to display average
time...So for example if we have 8 students...currently logged on I want to
display the average logged time.

Something like

averagetime = (PrevNow - Now())/student_no

Then process it to same meaningfull time as in 1.

Can someone give me any hints!! please...

Thanks
Jason

----------------------------------------------------------
"My software never has bugs. It just develops random features."



Thu, 22 Jul 2004 11:41:07 GMT  
 formatting (Now() - time) to hh:mm:ss ... lost?!
If you are working with times and not dates shouldn't you use
the Time function instead of Now?

Maybe the TimeSerial or FormatDateTime function could do
what you want.

Bill Wallace


Quote:
> Hi

> I need some help with processing time with the Now() function...

> What I have going at the moment is that when a student first logs
in...that
> time is recorded using Now() and stored in access.  I retrieve this value
> during processing of a ASP page and store it in a variable called PrevNow

> I do a couple of things with this.

> 1.  A admin can then query for how long the student has been logged on
for..

> So I have something like

> loggedtime = PrevNow - Now()

> then I want to format this number loggedtime into something meaningfull
like
> hh:mm:ss...I've tried format...and some dozen variations but I can't
produce
> anything that looks pretty.

> 2. On the same vein....I would also like to be able to display average
> time...So for example if we have 8 students...currently logged on I want
to
> display the average logged time.

> Something like

> averagetime = (PrevNow - Now())/student_no

> Then process it to same meaningfull time as in 1.

> Can someone give me any hints!! please...

> Thanks
> Jason

> ----------------------------------------------------------
> "My software never has bugs. It just develops random features."



Thu, 22 Jul 2004 12:33:12 GMT  
 formatting (Now() - time) to hh:mm:ss ... lost?!
Thanks Bill

I'll give those functions a spin....


Quote:
> If you are working with times and not dates shouldn't you use
> the Time function instead of Now?

> Maybe the TimeSerial or FormatDateTime function could do
> what you want.

> Bill Wallace



> > Hi

> > I need some help with processing time with the Now() function...

> > What I have going at the moment is that when a student first logs
> in...that
> > time is recorded using Now() and stored in access.  I retrieve this
value
> > during processing of a ASP page and store it in a variable called
PrevNow

> > I do a couple of things with this.

> > 1.  A admin can then query for how long the student has been logged on
> for..

> > So I have something like

> > loggedtime = PrevNow - Now()

> > then I want to format this number loggedtime into something meaningfull
> like
> > hh:mm:ss...I've tried format...and some dozen variations but I can't
> produce
> > anything that looks pretty.

> > 2. On the same vein....I would also like to be able to display average
> > time...So for example if we have 8 students...currently logged on I want
> to
> > display the average logged time.

> > Something like

> > averagetime = (PrevNow - Now())/student_no

> > Then process it to same meaningfull time as in 1.

> > Can someone give me any hints!! please...

> > Thanks
> > Jason

> > ----------------------------------------------------------
> > "My software never has bugs. It just develops random features."



Thu, 22 Jul 2004 17:45:29 GMT  
 formatting (Now() - time) to hh:mm:ss ... lost?!
Something like this might get you started.

It looks weird, but seems to produce the desired result.

The +'s after the logoff are just to add some hours, minutes, seconds

--
Regards

Michael Dunn

Option Explicit

Dim i, x
Dim LogOn(4), LogOff(4), TimeLoggedOn(4)
Dim TotalTimeOn

LogOn(0) = Time
LogOn(1) = Time
LogOn(3) = Time
LogOn(4) = Time

LogOff(0) = Time + 5/1440
LogOff(1) = Time + 110/1440
LogOff(3) = Time + 15/1440 + 5/86400
LogOff(4) = Time + 320/1440

For i = LBound(LogOn) to UBound(LogOn)
 If LogOn(i) <> "" Then
  TimeLoggedOn(i) = DateDiff("s", Logon(i), LogOff(i))
  TotaltimeOn = TotalTimeOn + TimeLoggedOn(i)
  x = x + 1
 End If
Next

MsgBox "Total time logged on = " & ConvertToTime(TotalTimeOn) & vbCr _
 & "Average time logged on, for " & x & " students = " & ConvertToTime(TotalTimeOn\x)

'-------------------

Private Function ConvertToTime(Seconds)
Dim hhnn, ss

hhnn = FormatDateTime(Seconds/86400, 4)
If Seconds Mod 60 > 9 Then
 ss = Seconds Mod 60
Else ss = "0" & Seconds Mod 60
End If

ConvertToTime = hhnn & ":" & ss

End Function

Quote:

> Hi

> I need some help with processing time with the Now() function...

> What I have going at the moment is that when a student first logs in...that
> time is recorded using Now() and stored in access.  I retrieve this value
> during processing of a ASP page and store it in a variable called PrevNow

> I do a couple of things with this.

> 1.  A admin can then query for how long the student has been logged on for..

> So I have something like

> loggedtime = PrevNow - Now()

> then I want to format this number loggedtime into something meaningfull like
> hh:mm:ss...I've tried format...and some dozen variations but I can't produce
> anything that looks pretty.

> 2. On the same vein....I would also like to be able to display average
> time...So for example if we have 8 students...currently logged on I want to
> display the average logged time.

> Something like

> averagetime = (PrevNow - Now())/student_no

> Then process it to same meaningfull time as in 1.

> Can someone give me any hints!! please...

> Thanks
> Jason

> ----------------------------------------------------------
> "My software never has bugs. It just develops random features."



Fri, 23 Jul 2004 17:07:02 GMT  
 formatting (Now() - time) to hh:mm:ss ... lost?!
You could try this

Dim tTime

if Hour(loggedtime) < 10 then
  tTime = "0" & Hour(loggedtime)
else
  tTime =  Hour(loggedtime)
end if

 tTime = tTime & ":"

if Minute(loggedtime) < 10 then
  tTime = tTime & "0" & Minute(loggedtime)
else
  tTime = tTime &  Minute(loggedtime)
end if

 tTime = tTime & ":"

if Second(loggedtime) < 10 then
  tTime = tTime & "0" & Second(loggedtime)
else
  tTime = tTime &  Second(loggedtime)
end if


Quote:
> Hi

> I need some help with processing time with the Now() function...

> What I have going at the moment is that when a student first logs
in...that
> time is recorded using Now() and stored in access.  I retrieve this value
> during processing of a ASP page and store it in a variable called PrevNow

> I do a couple of things with this.

> 1.  A admin can then query for how long the student has been logged on
for..

> So I have something like

> loggedtime = PrevNow - Now()

> then I want to format this number loggedtime into something meaningfull
like
> hh:mm:ss...I've tried format...and some dozen variations but I can't
produce
> anything that looks pretty.

> 2. On the same vein....I would also like to be able to display average
> time...So for example if we have 8 students...currently logged on I want
to
> display the average logged time.

> Something like

> averagetime = (PrevNow - Now())/student_no

> Then process it to same meaningfull time as in 1.

> Can someone give me any hints!! please...

> Thanks
> Jason

> ----------------------------------------------------------
> "My software never has bugs. It just develops random features."



Sat, 24 Jul 2004 03:21:36 GMT  
 formatting (Now() - time) to hh:mm:ss ... lost?!
Didn't allow for total time in excess of 24 hours

Try this

--
Regards

Michael Dunn

Option Explicit

Dim i, x
Dim LogOn(4), LogOff(4), TimeLoggedOn(4)
Dim TotalTimeOn

LogOn(0) = Time
LogOn(1) = Time
LogOn(3) = Time
LogOn(4) = Time

LogOff(0) = Time + 5/1440
LogOff(1) = Time + 110/1440
LogOff(3) = Time + 15/1440 + 5/86400
LogOff(4) = Time + 15320/1440

For i = LBound(LogOn) to UBound(LogOn)
 If LogOn(i) <> "" Then
  TimeLoggedOn(i) = DateDiff("s", Logon(i), LogOff(i))
  TotaltimeOn = TotalTimeOn + TimeLoggedOn(i)
  x = x + 1
 End If
Next

MsgBox "Total time logged on = " & ConvertToTime(TotalTimeOn) & vbCr _
 & "Average time logged on, for " & x & " students = " & ConvertToTime(TotalTimeOn\x)

'-------------------

Private Function ConvertToTime(ByVal Seconds)
Dim  dd, hhnn, ss

If Seconds > 86400 then
 dd = Seconds\86400
 Seconds = Seconds - dd * 86400
 If dd < 10 then dd = "0" & dd
End If

hhnn = FormatDateTime(Seconds/86400, 4)

ss = Seconds Mod 60
If ss < 10 Then ss = "0" & ss

If dd ="" then
 ConvertToTime = hhnn & ":" & ss
else
 ConvertToTime = dd & ":" & hhnn & ":" & ss
End If

End Function

: Something like this might get you started.
:
: It looks weird, but seems to produce the desired result.
:
: The +'s after the logoff are just to add some hours, minutes, seconds
:
:
: --
: Regards
:
: Michael Dunn
:
:
: Option Explicit
:
: Dim i, x
: Dim LogOn(4), LogOff(4), TimeLoggedOn(4)
: Dim TotalTimeOn
:
: LogOn(0) = Time
: LogOn(1) = Time
: LogOn(3) = Time
: LogOn(4) = Time
:
: LogOff(0) = Time + 5/1440
: LogOff(1) = Time + 110/1440
: LogOff(3) = Time + 15/1440 + 5/86400
: LogOff(4) = Time + 320/1440
:
: For i = LBound(LogOn) to UBound(LogOn)
:  If LogOn(i) <> "" Then
:   TimeLoggedOn(i) = DateDiff("s", Logon(i), LogOff(i))
:   TotaltimeOn = TotalTimeOn + TimeLoggedOn(i)
:   x = x + 1
:  End If
: Next
:
: MsgBox "Total time logged on = " & ConvertToTime(TotalTimeOn) & vbCr _
:  & "Average time logged on, for " & x & " students = " & ConvertToTime(TotalTimeOn\x)
:
: '-------------------
:
: Private Function ConvertToTime(Seconds)
: Dim hhnn, ss
:
: hhnn = FormatDateTime(Seconds/86400, 4)
: If Seconds Mod 60 > 9 Then
:  ss = Seconds Mod 60
: Else ss = "0" & Seconds Mod 60
: End If
:
: ConvertToTime = hhnn & ":" & ss
:
: End Function
:
:
:
: > Hi
: >
: > I need some help with processing time with the Now() function...
: >
: > What I have going at the moment is that when a student first logs in...that
: > time is recorded using Now() and stored in access.  I retrieve this value
: > during processing of a ASP page and store it in a variable called PrevNow
: >
: > I do a couple of things with this.
: >
: > 1.  A admin can then query for how long the student has been logged on for..
: >
: > So I have something like
: >
: > loggedtime = PrevNow - Now()
: >
: > then I want to format this number loggedtime into something meaningfull like
: > hh:mm:ss...I've tried format...and some dozen variations but I can't produce
: > anything that looks pretty.
: >
: >
: > 2. On the same vein....I would also like to be able to display average
: > time...So for example if we have 8 students...currently logged on I want to
: > display the average logged time.
: >
: > Something like
: >
: > averagetime = (PrevNow - Now())/student_no
: >
: > Then process it to same meaningfull time as in 1.
: >
: > Can someone give me any hints!! please...
: >
: > Thanks
: > Jason
: >
: > ----------------------------------------------------------
: > "My software never has bugs. It just develops random features."
: >
: >
:
:



Sat, 24 Jul 2004 06:42:17 GMT  
 formatting (Now() - time) to hh:mm:ss ... lost?!


Quote:
> You could try this

> Dim tTime

> if Hour(loggedtime) < 10 then
>   tTime = "0" & Hour(loggedtime)
> else
>   tTime =  Hour(loggedtime)
> end if

>  tTime = tTime & ":"

> if Minute(loggedtime) < 10 then
>   tTime = tTime & "0" & Minute(loggedtime)
> else
>   tTime = tTime &  Minute(loggedtime)
> end if

>  tTime = tTime & ":"

> if Second(loggedtime) < 10 then
>   tTime = tTime & "0" & Second(loggedtime)
> else
>   tTime = tTime &  Second(loggedtime)
> end if



>> Hi

>> I need some help with processing time with the Now() function...

>> What I have going at the moment is that when a student first logs
>> in...that time is recorded using Now() and stored in access.  I
>> retrieve this value during processing of a ASP page and store it in a
>> variable called PrevNow

>> I do a couple of things with this.

>> 1.  A admin can then query for how long the student has been logged on
>> for..

>> So I have something like

>> loggedtime = PrevNow - Now()

>> then I want to format this number loggedtime into something
>> meaningfull like hh:mm:ss...I've tried format...and some dozen
>> variations but I can't produce anything that looks pretty.

>> 2. On the same vein....I would also like to be able to display average
>> time...So for example if we have 8 students...currently logged on I
>> want to display the average logged time.

>> Something like

>> averagetime = (PrevNow - Now())/student_no

>> Then process it to same meaningfull time as in 1.

>> Can someone give me any hints!! please...

>> Thanks
>> Jason

>> ----------------------------------------------------------
>> "My software never has bugs. It just develops random features."

'This is not too structured but it works. I am sure there are 100 more
'efficient ways to do this. I am new to this :)
Dim a ,b ,c, nm, firstTime, SecondTime
set WshShell = WScript.CreateObject("WScript.Shell")

nm = Inputbox ("UserName")
firstTime = Now() 'Logon time
a = GetSec() 'start time in seconds
WScript.echo "Simulating work"
secondTime = Now() 'end time in seconds
b = GetSec()
'WScript.Echo b
c= b-a
'WScript.Echo "Difference = " & c
d = ConTime(c)
WScript.Echo nm & vbcrlf & "Logged in: " & firstTime & vbcrlf & "Logged
out: " & SecondTime & Vbcrlf &"logged time = " &d

Function ConTime(Diff) 'Function to format time as hh:mm:ss
Dim hr, mn , sc
hr = int(diff/3600)
if hr < 10 then
hr = "0" & hr
end if
mn = int((diff - (hr*3600))/60)
if mn < 10 then
mn = "0" & mn
end if
sc = diff - hr*3600 - mn*60
if sc < 10 then
sc = "0" & sc
end if
ConTime = hr &":" & mn & ":" & sc
End Function

Function GetSec() 'Function to get time and convert to seconds
Dim MyDay, MyHour, MyMin, MySec
MyDay = date
MyHour= Hour(Now) * 3600
MyMin = Minute(Now) * 60
MySec = Second(Now)
GetSec = MyHour+MyMin+MySec+MyMilli
End Function'



Sat, 24 Jul 2004 15:03:48 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. EGA rows/cols?

2. Time() returning hh:mm:ss tt and not HH:mm:ss

3. Variable Time Format HH:MM:SS

4. formatting (Now() - time) to hh:mm:ss ... lost?!

5. Combined Key Press (VK-CONTROL+VK-DELETE) - How To Capture

6. Is there a way to display multiple rows without using a DBGrid component?

7. Define errors:(

8. Precision in time hh:mm:ss:xx?

9. Converting Seconds to hh:mm:ss Format?

10. converting seconds to HH:mm:ss format

11. converting seconds to hh:mm:ss format

12. Can not filter items by RecievedTime = dd/mm/yyyy hh:mm:ss

 

 
Powered by phpBB® Forum Software