Advice on comparing time intervals

  • Thread starter Thread starter Ted
  • Start date Start date
T

Ted

I need to compare two time intervals in both military and Long time formats.
I have an application which needs to toggle the fore color of the time
display if the current system time is prior to >= to 8 pm toggle color red
else toggle color green. Can anyone provide me with some advice on how to
accomplish this. Here some sample code:

Select Case Me!optgrpTime.Value
Case 1
Me!txtSysClock.Format = "Long Time"
strCurTime = CStr(Me!txtSysClock)
If CDate(strCurTime) >= CDate("8:00:00 PM") Then
Me!txtSysClock.ForeColor = 255
Else
Me!txtSysClock.ForeColor = 32768
End If
Case 2
Me!txtSysClock.Format = "hh:mm:ss"
strCurTime = CStr(Format(Me!txtSysClock, "hh:mm:ss"))
If CDate(strCurTime) >= CDate("20:00:00") Then
Me!txtSysClock.ForeColor = 255
Else
Me!txtSysClock.ForeColor = 32768
End If
End Select
 
I need to compare two time intervals in both military and Long time formats.
I have an application which needs to toggle the fore color of the time
display if the current system time is prior to >= to 8 pm toggle color red
else toggle color green. Can anyone provide me with some advice on how to
accomplish this. Here some sample code:

Select Case Me!optgrpTime.Value
Case 1
Me!txtSysClock.Format = "Long Time"
strCurTime = CStr(Me!txtSysClock)
If CDate(strCurTime) >= CDate("8:00:00 PM") Then
Me!txtSysClock.ForeColor = 255
Else
Me!txtSysClock.ForeColor = 32768
End If
Case 2
Me!txtSysClock.Format = "hh:mm:ss"
strCurTime = CStr(Format(Me!txtSysClock, "hh:mm:ss"))
If CDate(strCurTime) >= CDate("20:00:00") Then
Me!txtSysClock.ForeColor = 255
Else
Me!txtSysClock.ForeColor = 32768
End If
End Select

Wow. You're making it MUCH harder than it needs to be.

If Time() > #20:00# Then
Me!txtSysClock.ForeColor = vbRed
Else
ME!txtSysClock.ForeColor = vbGreen
End If

If you need to change the Format, remember that mm means the *Month* -
miNutes is "nn".

John W. Vinson[MVP]
 
John,
Thanks but when I try to put your code snippet in the module, the value
#20:00# changes to #8:00:00 PM#.
Allow to explain more....there is an option group with two radial buttons
one labeled standard time and another labeled military time. Which ever
option the user chooses toggles the format property of a text box which
displays the current, which is updated using the timer event. When the time
is between 7:30 am and 8:00 pm, I want the time color green. When the time
is between 8:00 pm and 7:30 am I need the time color to be red. My issue
lyes in determining the time range..it could be militray comparison or
standard time comparison depending on the option choosen and the format set
by the user. I appreciate your help.

Ted
 
John,
Thanks but when I try to put your code snippet in the module, the value
#20:00# changes to #8:00:00 PM#.

That is ABSOLUTELY IRRELEVANT.

THe value of #20:00# - what's actually stored in the table - is
0.83333333333333 (20/24 of a day). #8:00:00 PM# is another way of
depicting this time value. So is #8PM#.
Allow to explain more....there is an option group with two radial buttons

"radio" buttons, from the old days when a car radio had five or six
station-select buttons, only one of which could be pushed.
one labeled standard time and another labeled military time. Which ever
option the user chooses toggles the format property of a text box which
displays the current, which is updated using the timer event. When the time
is between 7:30 am and 8:00 pm, I want the time color green. When the time
is between 8:00 pm and 7:30 am I need the time color to be red. My issue
lyes in determining the time range..it could be militray comparison or
standard time comparison depending on the option choosen and the format set
by the user. I appreciate your help.

You're mistaken. You're confusing data STORAGE with data DISPLAY. A
time value *is a time value* no matter how it's displayed. Your
previous post did not mention the time between midnight and 7:30;
given that additional constraint, try

If Time() >= #07:30# AND Time() < #08:00# Then
control.ForeColor = vbGreen
Else
control.ForeColor = vbRed
End If

John W. Vinson[MVP]
 
Back
Top