Time Check

Find out if the current time is between two preset time values.

Page 1 of 1

1 Replies - 7670 Views - Last Post: 13 April 2007 - 10:25 AM Rate Topic: -----

#1 hamsinv   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 13-April 07

Time Check

Posted 13 April 2007 - 03:45 AM

Hello there...

Am new to this forum. Feel like this is a good place to find help and share my knowledge..

I need to find if a given time falls under two predefined time values.
In the following code str1 holds the input from the user. str2 and str3 are preset time values. the if statement is used to compare the time values. But when i input time between 00:00:00 and 6:00:00, the msgbox is not displayed.
Is this the correct approach, if not how do i go about..

Dim str1 As Date, str2 As Date, str3 As Date
str1 = Text1.Text
str2 = TimeValue("00:00:00")
str3 = TimeValue("6:00:00") 
if (str1 >= str2) and (str1 <= str3) then
		msgbox "Time is within the preset period"

thanks for the help.... :^:

Is This A Good Question/Topic? 0
  • +

Replies To: Time Check

#2 Jayman   User is offline

  • Student of Life
  • member icon

Reputation: 421
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Time Check

Posted 13 April 2007 - 10:25 AM

You will need to convert the value retrieved from the TextBox from a string to a Date value.
		Dim str1 As Date, str2 As Date, str3 As Date
		str1 = TimeValue(Text1.Text)
		str2 = TimeValue("00:00:00")
		str3 = TimeValue("6:00:00")
		If (str1 >= str2) And (str1 <= str3) Then
			MsgBox("Time is within the preset period")
		End If

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1