Day of Week

Status
Not open for further replies.

Eric Osborn

Joined
Mar 24, 2017
Messages
26
Reaction score
0
Does someone know how to route based on day of week?

I'm looking to do the following---

Monday through Thursday from 9am to 5pm route to location A
Friday 9am to 8pm route to location B
Saturday and Sunday from 12pm to 8pm route to location C

Thank you!

Eric
 
Hey thank you for those.... From what I understand in other post he is using new Date().getDay() == 0 which should be for Sunday?

When I compile, I get the namespace "Date" could not be found. Tried couple other ways using Microsoft article but not getting it. Time of day I think I'm good with.

Eric
 
Wrong language. You need to use C# in the CFD.

You can use an integer compare (i.e. 0 = Sunday) but you should also be able to use the constants as below to make it more readable.
DateTime.Now.DayOfWeek == DayOfWeek.Sunday

You can also use other operators such as
DateTime.Now.DayOfWeek >= DayOfWeek.Monday && DateTime.Now.DayOfWeek <= DayOfWeek.Friday
Just remember that Sunday is the lowest day and Saturday is the highest

Test it (and other C# code) here: https://dotnetfiddle.net/7ghv7A
 
Last edited:
Hi Eric,

The articles that mention this:
new Date().getDay() == 0

Are referring to the old VAD for v14, which uses Javascript. In the CFD for v15 you can't use Javascript, and that's why you're getting that error. You need to use C# instead, as very well explained by @DL_.

Kind regards.
 
Thank you and DL thank for that outline! I will try this out today.
 
@dl @edossantos , Hey,

Could you tell me if I wrote this right? I'm not getting it to work correctly. We open at 11am daily, close at midnight Sunday through Thursday and 2am on Friday and Saturday nights.

((DateTime.Now.Hour >= 9 && DateTime.Now.Hour <= 24) || (DateTime.Now.DayOfWeek == DayOfWeek.Saturday && DateTime.Now.Hour <2) || (DateTime.Now.DayOfWeek == DayOfWeek.Sunday && DateTime.Now.Hour <2))

Thanks for your help!
 
Hi @Eric Osborn,

The expression looks good to me. I would just change:
DateTime.Now.Hour <= 24

to:
DateTime.Now.Hour < 24

Because the hour will never be 24. But anyway that will not cause a bug...

So this is not working for you? What problem are you experiencing?

Kind regards.
 
Status
Not open for further replies.

Forum statistics

Threads
111,864
Messages
589,455
Members
164,703
Latest member
eokwaro