Time difference and If function

G

Greg

I am trying to calculate difference betwen last update and current time:

Dim sngElapsedTime As Date
Dim Last_Update As Date
Dim sMsg As String

sMsg = " Please update" & " " & [Ticket #]
'determine the amount of time that has elapst between when the form
'was open and now.
sngElapsedTime = Now() - [Last Update]
'Update the timer
txtTimeDiff = Format(sngElapsedTime, "hh:mm")

How can I write if function that will display message after differnce is >
59 minutes?

Thanks
 
A

Allen Browne

Use DateDiff() to get the difference in whole minutes:

Dim lngMinutes As Long
lngMinutes = DateDiff("n", [Last Update], Now())

You can display that as hours an minutes with:
= lngMinutes \ 60 & Format(lngMinutes Mod 60, "\:00")
 
G

Greg

Thanks Allen however:
I am calculating time difference using
sngElapsedTime = Now() - [Last Update]
and everything is ok
Then i am updating time differnce every minute using on timer event
txtTimeDiff = Format(sngElapsedTime, "hh:mm")

I would like to write if function that will display message box after time
difference > 59 minutes. I dont know how to set this function.

If sngElapsedTime > 59 Then
MsgBox(sMsg, vbCritical .....
Msgbox is displayed even if difference is less then 59 minutes


Allen Browne said:
Use DateDiff() to get the difference in whole minutes:

Dim lngMinutes As Long
lngMinutes = DateDiff("n", [Last Update], Now())

You can display that as hours an minutes with:
= lngMinutes \ 60 & Format(lngMinutes Mod 60, "\:00")

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Greg said:
I am trying to calculate difference betwen last update and current time:

Dim sngElapsedTime As Date
Dim Last_Update As Date
Dim sMsg As String

sMsg = " Please update" & " " & [Ticket #]
'determine the amount of time that has elapst between when the form
'was open and now.
sngElapsedTime = Now() - [Last Update]
'Update the timer
txtTimeDiff = Format(sngElapsedTime, "hh:mm")

How can I write if function that will display message after differnce is >
59 minutes?

Thanks
 
B

Bob Quintal

Thanks Allen however:
I am calculating time difference using
sngElapsedTime = Now() - [Last Update]
and everything is ok

Everything is not ok, or you would not have posted your original
question, which Allen answered.

If you were to examine the result of your Now() - [Last Update],
you will see that it's the fractional part of the day.
That is 6 hours = .25. 1 hour is approx. 0.0416667

Do the calc as Allen showed you and you get a result in minutes,
which you can test with if intElapsedTime >= 60

Q
Then i am updating time differnce every minute using on timer
event txtTimeDiff = Format(sngElapsedTime, "hh:mm")

I would like to write if function that will display message box
after time difference > 59 minutes. I dont know how to set this
function.

If sngElapsedTime > 59 Then
MsgBox(sMsg, vbCritical .....
Msgbox is displayed even if difference is less then 59 minutes


Allen Browne said:
Use DateDiff() to get the difference in whole minutes:

Dim lngMinutes As Long
lngMinutes = DateDiff("n", [Last Update], Now())

You can display that as hours an minutes with:
= lngMinutes \ 60 & Format(lngMinutes Mod 60, "\:00")

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Greg said:
I am trying to calculate difference betwen last update and
current time:

Dim sngElapsedTime As Date
Dim Last_Update As Date
Dim sMsg As String

sMsg = " Please update" & " " & [Ticket #]
'determine the amount of time that has elapst between when
the form 'was open and now.
sngElapsedTime = Now() - [Last Update]
'Update the timer
txtTimeDiff = Format(sngElapsedTime, "hh:mm")

How can I write if function that will display message after
differnce is > 59 minutes?

Thanks
 
A

Allen Browne

That's correct: the method you are using will not work.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Greg said:
Thanks Allen however:
I am calculating time difference using
sngElapsedTime = Now() - [Last Update]
and everything is ok
Then i am updating time differnce every minute using on timer event
txtTimeDiff = Format(sngElapsedTime, "hh:mm")

I would like to write if function that will display message box after time
difference > 59 minutes. I dont know how to set this function.

If sngElapsedTime > 59 Then
MsgBox(sMsg, vbCritical .....
Msgbox is displayed even if difference is less then 59 minutes


Allen Browne said:
Use DateDiff() to get the difference in whole minutes:

Dim lngMinutes As Long
lngMinutes = DateDiff("n", [Last Update], Now())

You can display that as hours an minutes with:
= lngMinutes \ 60 & Format(lngMinutes Mod 60, "\:00")

Greg said:
I am trying to calculate difference betwen last update and current time:

Dim sngElapsedTime As Date
Dim Last_Update As Date
Dim sMsg As String

sMsg = " Please update" & " " & [Ticket #]
'determine the amount of time that has elapst between when the form
'was open and now.
sngElapsedTime = Now() - [Last Update]
'Update the timer
txtTimeDiff = Format(sngElapsedTime, "hh:mm")

How can I write if function that will display message after differnce
is >
59 minutes?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top