For my app I need to know if Now() is between two values.
The user can set a start- and an end-time so he will not disturbed by a notification (during the night for example).
So if have got two TimePickers (start- and end-time) that the user can set.
Lets say the user sets 22:00 for the StartTime and 07:00 for the EndTime (this would cover the night).
How can I check if the DateTime.Now is between the selected Start and End time?
EDIT:
I only want this to work with the Hour and minutes part. So if the user sets the Start and End time this should work for every night.
First you need to convert everything to the same units (we’ll use
TimeSpan), then you need to see whether the start-end times cross midnight, and finally do your comparison based on the results of that check:Here’s a function to do it for you:
You would call it like: