473,241 Members | 1,475 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,241 software developers and data experts.

Check, if a given time lies between two times regardless of date

Hi there,

I have time-of-day spans presented as strings and want to check, if, at
a given time, I am within such a time span.

Example: Timespan-string is given as follows: "09:00 , 16:00"

A function should now return true if the current time of day is between
9:00 and 16:00 and false otherwise.

Any help is appreciated. The problem sounds trivial, yet I currently
fail to come up with a pleasant solution.

cheers,

Mathias
Jun 27 '08 #1
2 8675
"Mathias Weyel" <ne**@josquin.orgwrote:
I have time-of-day spans presented as strings and want to check, if,
at a given time, I am within such a time span.
Example: Timespan-string is given as follows: "09:00 , 16:00"
A function should now return true if the current time of day is
between 9:00 and 16:00 and false otherwise.
string t = "09:00 , 16:00";

string start = t.Substring(0, 5), end = t.Substring(8, 5);
string now = DateTime.Now.ToString("HH:mm");

return (now >= start && now <= end);

Eq.
Jun 27 '08 #2
Mathias Weyel wrote:
Hi there,

I have time-of-day spans presented as strings and want to check, if, at
a given time, I am within such a time span.

Example: Timespan-string is given as follows: "09:00 , 16:00"

A function should now return true if the current time of day is between
9:00 and 16:00 and false otherwise.

Any help is appreciated. The problem sounds trivial, yet I currently
fail to come up with a pleasant solution.
It is fairly trivial: just parse out the actual TimeSpans you want out of
timespan-string so that you have two strings: one containing "09:00" and another
containing "16:00". Create TimeSpans with them them (TimeSpan.Parse), and return
whether DateTime.Now.TimeOfDay is between them.

Chris.
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: CrystalDBA | last post by:
I am using SQL Server 2000. I need to query my database for all the contracts that came in during a certain time frame (user is prompted for reportingperiodid). Table - Periods Fields -...
1
by: Lei Guangfu | last post by:
Hi, I have a program need to check the value of a application available, and then decide whether to execute codes followed. In order to achieve this purpose, I use DO WHILE loop to judge the...
1
by: Lei Guangfu | last post by:
Hi, I have a program need to delay for a given time, I use DO WHILE loop to achieve this goal, but this method consumes too much CPU resource. So I want to find a way to pause a process for a...
2
by: Noozer | last post by:
I have a textbox on one of my forms that is used to accept a time from the user. I need to write this value to a database to trigger an event later on. What I'd like to know is... Are there...
7
by: geo039 | last post by:
I have a simple application that takes user input by text and time selected by date time picker. It displays the appt description in one list box and the time in another list box. I need a simple...
3
by: Mark Ingram | last post by:
Hi, I'd like to know the best way of checking the current time during a demonstration product. At the minute i store the first run date, then compare that to the system time, but obviously a user...
13
by: dizzydangler | last post by:
Just a quick question...I'm running an MS Access 2007 db that tracks appointments in a single table. Date and time are entered as separate fields in short date (mm/dd/yyyy) and short time (hh:mm)...
1
by: sasasasa | last post by:
How can I loop through each date in a given time period so that I can add those dates as a column name in a table. I want to create datatable with the person's name and hours he worked in a given...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.