Click here to Skip to main content
15,889,536 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What I need help with is (if statements) how to determine which method to use (to run a process) based on specified weekday time. Dates are irrelevant.
How do I use specified time to decide the method to use?
I do not need help with the process or even the methods. All I need help with is if statements to determine which method to use.

The two methods AllDocuments and GetDocsInLast60Minutes will be used based on specified times.

Requirements
Method AllDocuments
If the time is 8 AM to 9 AM AllDocuments method is used
If the time is 11 AM - 11:05 AM AllDocuments method is used
If the time is 1 PM - 1:05 PM AllDocuments method is used
If the time is 3 PM - 3:05 PM AllDocuments method is used
If the time is 5 PM - 5:05 PM AllDocuments method is used


Method GetDocsInLast60Minutes
If the time is 9 AM to 5 PM GetDocsInLast60Minutes method is used

What I have tried:

I am not sure how to go about the if statements
VB
If (time is 8AM to 9AM) Then
Use GetDocsInLast60Minutes 

If (time is between 11 AM and 11:05 AM ) Then
Use AllDocuments
'etc
Posted
Updated 8-Feb-17 16:43pm

Use a DateTime Structure (System)[^], which allows you to get hours, minutes etc.
 
Share this answer
 
Comments
Member 11403304 8-Feb-17 11:19am    
Richard could you please give me an example of how to at least do one if statement for when time is 8AM to 9AM?
Richard MacCutchan 8-Feb-17 11:34am    
There are plenty of samples that you can study on the MSDN page I gave you.
Peter Leow 8-Feb-17 22:45pm    
5ed for given OP an important head start. I have provided an example to guide him a bit.
To start off, use 24 hours time instead of am pm. So for the time slot of 1:00pm to 1:05pm, express it as 13 hr 0 minute to 13 hr 5 minute in the code.
Based on your description, you are only interested in hour and minute parts of the time. So the question is really which time slot the current hour and current minute in, right? This lead us to how to find the current hour and current minute. Look through the reference link that Richard has given you, can you find the right methods?
1. Find current date using DateTime.Now Property[^]
2. Find current hour from the current date using DateTime.Hour Property (System)[^]
3. Find current minute from current date using DateTime.Minute Property (System)[^]
4. The rest is just maths couple with if else statements, e.g.
Imports System
				
Public Module Module1
	Public Sub Main()
		
		Dim now As Date = Date.Now
		
		Dim hour As Integer = now.Hour
		Dim minute As Integer = now.Minute
		
		Console.WriteLine(hour)
		Console.WriteLine(minute)

		If hour = 13 And minute <= 5  Then
			Console.WriteLine("Run method A")
        Else
            Console.WriteLine("Run method B")
        End If
		
	End Sub
End Module
Refer to the link by Richard if you seek further manipulation of date time. One way to learn coding is to refer to the document and experiment with the various methods.
 
Share this answer
 
Comments
Richard MacCutchan 9-Feb-17 4:06am    
And 5 for your clear explanation.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900