Need some very easy vbscript help (see inside)

Soldato
Joined
1 Dec 2004
Posts
23,079
Location
S.Wales
Im creating a xmas opening script using vbscript to bolt onto our VoIP system call routing script. It all works perfectly. I have posted a section of the code below:

Code:
Function CheckDateTime(current)
	current = CDate(current)
	
	'
	' Prepare useful variables...
	Dim xday, xmonth, xhour, xminute
	xhour = Hour(current)	
	
	CheckDateTime = 0
		
	'Normal working day
	If (xhour >=8 and xhour <17 and xminute<30) Then 
		CheckDateTime = 1
	End If
	
	'Christmas period
	If (current >= CDate("24/12/2009 12:00PM") and current <= CDate("04/01/2010 08:00AM")) Then
		CheckDateTime = 2
		
		'25th December
		If (current >= CDate("25/12/2009 00:01AM") and current <= CDate("25/12/2009 23:59PM")) Then
			CheckDateTime = 3
		End If


Concentrate on the section

Code:
'Normal working day
	If (xhour >=8 and xhour <17 and xminute<30) Then 
		CheckDateTime = 1
	End If

Would this be the correct way to represent 08:00 > 17:30 ?? I know the 08:00 > 17:00 works fine, but I added the xminute as our actual closing time is 17:30.

Will this work or will I have to represent this 30 minutes another way?
 
I would have thought that would only work at the following times:

8:00-8:29
9:00-9:29
10:00-10:29
...


I would try:
Code:
'Normal working day
	If (xhour >=8 and xhour <17) Then 
		CheckDateTime = 1
	Elseif (xhour =17 and xminute <30) Then
		CheckDateTime = 1
	End If

Which would cover 8:00-17:00, and then 17:00-17:30 as two separate scenarios.
 
Hi,

Code:
If (xhour >=8) and (xhour <17 and xminute<30) Then


Should do it (up until 5:29pm anyway).

Can't see where you are setting the xminute though?
 
I would have thought that would only work at the following times:

8:00-8:29
9:00-9:29
10:00-10:29
...


I would try:
Code:
'Normal working day
	If (xhour >=8 and xhour <17) Then 
		CheckDateTime = 1
	Elseif (xhour =17 and xminute <30) Then
		CheckDateTime = 1
	End If

Which would cover 8:00-17:00, and then 17:00-17:30 as two separate scenarios.

Thanks for this, I shall give it a blast tomorrow :)

I created this script over a year ago for a company i used to work for who had about 6 call centres each with very annoying opening times/closing times/routing to mobiles etc

So frustrating :(

Least ours is simples :)

"Its xmas, naff off :D"
 
I would try:
Code:
'Normal working day
	If (xhour >=8 and xhour <17) Then 
		CheckDateTime = 1
	Elseif (xhour =17 and xminute <30) Then
		CheckDateTime = 1
	End If

Which would cover 8:00-17:00, and then 17:00-17:30 as two separate scenarios.

This works great :)

Thanks
 
Ahh, there we go, slight modification needed, here is the full script for those interested

Code:
'Copyright dmoranda.co.uk

TestCase(Date & " " & Time)
Testcase("23/12/2009 8:00AM")
Testcase("23/12/2009 17:00PM")
Testcase("23/12/2009 17:35PM")
Testcase("24/12/2009 8:00AM")
TestCase("24/12/2009 12:05PM")
Testcase("25/12/2009 8:00AM")
Testcase("26/12/2009 8:00AM")
Testcase("27/12/2009 9:00AM")
Testcase("28/12/2009 10:00AM")	
Testcase("29/12/2009 8:00AM")	
Testcase("30/12/2009 8:00AM")	
Testcase("31/12/2009 8:00AM")
Testcase("01/01/2010 8:00AM")	
Testcase("02/01/2010 8:00AM")			
Testcase("02/01/2010 17:59PM")	
Testcase("02/01/2010 18:01PM")
Testcase("03/01/2010 08:00AM")
Testcase("03/01/2010 18:01PM")
Testcase("04/01/2010 06:00AM")
Testcase("04/01/2010 08:01AM")
	


Function TestCase(datetime)
	MsgBox "Outcome for " & datetime & " = " & CheckDateTime(datetime)
End Function


' This method returns true if the service will be open at the specified date/time, or False if the service will be closed.
'1 = Call goto Agent, 2 = Call goto TAS, 3 = Call goto office closed annoucement

Function CheckDateTime(current)
	current = CDate(current)
	
	'
	' Prepare useful variables...
	Dim xday, xmonth, xhour, xminute
	xhour = Hour(current)	
	xminute = Minute(current)
	
	CheckDateTime = 0
	
	'*Use the below code if closing time falls on the hour*	
	'Normal working day
	'If (xhour >=8 and xhour <17 and xminute<30) Then 
		'CheckDateTime = 1
	'End If
	
	'*Use the below code if closing time falls during the hour*
	'Normal working day
	If (xhour >=8 and xhour <17) Then 
		CheckDateTime = 1
	Elseif (xhour =17 and xminute <30) Then
		CheckDateTime = 1
	Else 
		CheckDateTime = 2
	End If
	
	
	
	'Christmas period
	If (current >= CDate("24/12/2009 12:00PM") and current <= CDate("04/01/2010 08:00AM")) Then
		CheckDateTime = 2
		
		'25th December
		If (current >= CDate("25/12/2009 00:01AM") and current <= CDate("25/12/2009 23:59PM")) Then
			CheckDateTime = 3
		End If
		
		'26th December
		If (current >= CDate("26/12/2009 00:01AM") and current <= CDate("26/12/2009 23:59PM")) Then
			CheckDateTime = 2
		End If
		
		'27th December
		If (current >= CDate("27/12/2009 00:01AM") and current <= CDate("27/12/2009 23:59PM")) Then
			CheckDateTime = 2
		End If
						
		'28th December 
		If (current >= CDate("28/12/2009 00:01AM") and current <= CDate("28/12/2009 23:59PM")) Then
			CheckDateTime = 2
		End If
		
		'29th December 
		If (current >= CDate("29/12/2009 00:01AM") and current <= CDate("29/12/2009 23:59PM")) Then
			CheckDateTime = 2
		End If
				
		'29th December 
		If (current >= CDate("30/12/2009 00:01AM") and current <= CDate("30/12/2009 23:59PM")) Then
			CheckDateTime = 2
		End If
		
		'30th December 
		If (current >= CDate("30/12/2009 00:01AM") and current <= CDate("30/12/2009 23:59PM")) Then
			CheckDateTime = 2
		End If

		'31st December 
		If (current >= CDate("31/12/2009 00:01AM") and current <= CDate("31/12/2009 23:59PM")) Then
			CheckDateTime = 2
		End If
		
		'1st January
		If (current >= CDate("01/01/2010 00:01AM") and current <= CDate("01/01/2010 23:59PM")) Then
			CheckDateTime = 3
		End If
		
		'2nd January
		If (current >= CDate("02/01/2010 00:01AM") and current <= CDate("02/01/2010 23:59PM")) Then
			CheckDateTime = 2
		End If
		
		'3rd January
		If (current >= CDate("03/01/2010 00:01AM") and current <= CDate("03/01/2010 23:59PM")) Then
			CheckDateTime = 2
		End If
		
		'4th January Early Morning
		If (current >= CDate("04/01/2010 00:01AM") and current <= CDate("04/01/2010 08:00AM")) Then
			CheckDateTime = 2
		End If
		
		'4th January Working Day
		If (current >= CDate("04/01/2010 08:01AM") and current <= CDate("04/01/2010 17:30PM")) Then
				CheckDateTime = 1
		End If 
		
		
	End If
	
End Function

Code:
'*Use the below code if closing time falls during the hour*
	'Normal working day
	If (xhour >=8 and xhour <17) Then 
		CheckDateTime = 1
	Elseif (xhour =17 and xminute <30) Then
		CheckDateTime = 1
	Else 
		CheckDateTime = 2
	End If
 
Back
Top Bottom