473,947 Members | 3,521 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Time Range Calculation?

I'm trying to find out if now() is between 9:00 AM and 5:00 PM I've tried
a few things but can't get it to work.

Thanks
Nov 21 '05 #1
11 8006
In message <uA************ **@TK2MSFTNGP14 .phx.gbl>, Bdog
<bd***@Hotmail. com> writes
I'm trying to find out if now() is between 9:00 AM and 5:00 PM I've tried
a few things but can't get it to work.


Have you tried:

IF Hour(Now) >= 9 AND Hour(Now) <= 17 THEN
' Do Something
END IF
--
Andrew D. Newbould E-Mail: ne********@NOSP AMzadsoft.com

ZAD Software Systems Web : www.zadsoft.com
Nov 21 '05 #2
Thanks I'll try it, any idea on how to handle it if I want from 8:30 to
4:30?

Thanks

Barclay

"Andrew D. Newbould" <ne********@NOz adSPANsoft.com> wrote in message
news:uo******** ******@zadsoft. gotadsl.co.uk.. .
In message <uA************ **@TK2MSFTNGP14 .phx.gbl>, Bdog
<bd***@Hotmail. com> writes
I'm trying to find out if now() is between 9:00 AM and 5:00 PM I've trieda few things but can't get it to work.


Have you tried:

IF Hour(Now) >= 9 AND Hour(Now) <= 17 THEN
' Do Something
END IF
--
Andrew D. Newbould E-Mail: ne********@NOSP AMzadsoft.com

ZAD Software Systems Web : www.zadsoft.com

Nov 21 '05 #3
On 2005-06-08, Bdog <bd***@Hotmail. com> wrote:
Thanks I'll try it, any idea on how to handle it if I want from 8:30 to
4:30?

Thanks

Barclay

Barclay, look at the DateTime objects compare method...

Dim begin As New Date _
(DateTime.Now.Y ear, DateTime.Now.Mo nth, DateTime.Now.Da y, 8, 30, 0)
Dim end As New Date _
(DateTime.Now.Y ear, DateTime.Now.Mo nth, DateTime.Now.Da y, 16, 30, 0)

Dim currentTime As Date = Date.Now ()
If Date.Compare (currentTime, begin) >= 0 And _
Date.Compare (currentTime, end) <= 0 Then
' Do Cool Stuff
End If

If you don't want it to be inclusive, then remove the equal signs :)
--
Tom Shelton [MVP]
Nov 21 '05 #4
Bdog,
I'm trying to find out if now() is between 9:00 AM and 5:00 PM I've
tried
a few things but can't get it to work.

I take for this the approach, that I first take the ticks from those values
and than compare those.

In my opinion is that the most easy way doing this.

I hope this helps,

Cor
Nov 21 '05 #5
In message <u0************ **@TK2MSFTNGP14 .phx.gbl>, Cor Ligthert
<no************ @planet.nl> writes
Bdog,
I'm trying to find out if now() is between 9:00 AM and 5:00 PM I've
tried
a few things but can't get it to work.

I take for this the approach, that I first take the ticks from those values
and than compare those.

In my opinion is that the most easy way doing this.

I hope this helps,

Cor


Or just look at the other Date functions like Minute, Seconds, Month,
Day, Year etc.
--
Andrew D. Newbould E-Mail: ne********@NOSP AMzadsoft.com

ZAD Software Systems Web : www.zadsoft.com
Nov 21 '05 #6
Andrew,

Or just look at the other Date functions like Minute, Seconds, Month, Day,
Year etc.


Than you have to compare every part indivially with the ticks you do it in
one time.

See this sample that I made for this question.

\\\
Dim datenow As DateTime = Now
Dim datefive As DateTime = _
New DateTime(Now.Ye ar, Now.Month, Now.Day, 17, 0, 0)
Dim datenine As DateTime = _
New DateTime(Now.Ye ar, Now.Month, Now.Day, 9, 0, 0)
If datenow.Ticks < datefive.Ticks AndAlso _
datenow.Ticks > datenine.Ticks Then
MessageBox.Show ("The time is between nine and five")
End If
///

Although I find your sample using the Microsoft.Visua lBasic namespace very
nice, does this go as well for minutes or even seconds.

Therefore if the problem is exactly as it is. I would go for your sample.
This ticks answer I write forever because it gives never problems. (For the
sample from Tom this is only an alternative showed because of the sentence
before )

Cor
Nov 21 '05 #7
Thanks for all your help guys, I'll give it a shot.

Barclay

"Cor Ligthert" <no************ @planet.nl> wrote in message
news:Oh******** ******@tk2msftn gp13.phx.gbl...
Andrew,

Or just look at the other Date functions like Minute, Seconds, Month, Day, Year etc.

Than you have to compare every part indivially with the ticks you do it in
one time.

See this sample that I made for this question.

\\\
Dim datenow As DateTime = Now
Dim datefive As DateTime = _
New DateTime(Now.Ye ar, Now.Month, Now.Day, 17, 0, 0)
Dim datenine As DateTime = _
New DateTime(Now.Ye ar, Now.Month, Now.Day, 9, 0, 0)
If datenow.Ticks < datefive.Ticks AndAlso _
datenow.Ticks > datenine.Ticks Then
MessageBox.Show ("The time is between nine and five")
End If
///

Although I find your sample using the Microsoft.Visua lBasic namespace very
nice, does this go as well for minutes or even seconds.

Therefore if the problem is exactly as it is. I would go for your sample.
This ticks answer I write forever because it gives never problems. (For

the sample from Tom this is only an alternative showed because of the sentence before )

Cor

Nov 21 '05 #8
Bdog,
I defined a TimeRange type that is useful to check to see if a DateTime
falls within a certain Time Range (for example between 8AM & 5PM). See:

http://groups-beta.google.com/group/...9aa87555043055

Using TimeRange you could do something like:

Static workHours As New TimeRange(#8:00 :00 AM#, #5:00:00 PM#)

If workHours.Conta ins(DateTime.No w) Then

End If

Hope this helps
Jay
"Bdog" <bd***@Hotmail. com> wrote in message
news:uA******** ******@TK2MSFTN GP14.phx.gbl...
| I'm trying to find out if now() is between 9:00 AM and 5:00 PM I've
tried
| a few things but can't get it to work.
|
| Thanks
|
|
Nov 21 '05 #9
"Bdog" <bd***@Hotmail. com> wrote in message
news:uA******** ******@TK2MSFTN GP14.phx.gbl...
I'm trying to find out if now() is between 9:00 AM and 5:00 PM


Format them all up as 24-hour times and compare - something like

sStart = dtStart.ToStrin g( "HH:mm" )
sEnd = dtEnd.ToString( "HH:mm" )
sNow = Now().ToString( "HH:mm" )

Select Case sNow
Case sStart To sEnd
' Yep!
Case Else
End Select

HTH,
Phill W.
Nov 21 '05 #10

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

Similar topics

2
5241
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much appreciated. TIA
96
4046
by: John Harrison | last post by:
I knew that unsigned integral data types were the cause of scads of mostly spurious warning messages, but I didn't realise that they were a security risk too (see here http://www.securitytracker.com/alerts/2004/Feb/1009067.html). All for one measly extra bit. So has the time come for C++ to deprecate unsigned integral types? john
1
1774
by: John Feeley | last post by:
am tring to add a number of years to a dob. im doing this by adding my date+years*365.26 I get a string of numbers. I then convert the number in the next column to actual date again. I'm getting the correct date. Now I want my criteria on that column to allow me to return only date in a given to from period of my choosing. I try the between_and functions but nothing is returned. I'm guessing it's because the column is still a calculation...
2
3604
by: Jerry | last post by:
I am rewriting my vba routines to C# to increase speed. I have been unable to find any help on how to pass ranges to C#. Excel function that was called in VBA =CalcRows(A1,A2,B1:B140,C1:C140,D1:D140) A1 holds the type of calculation to perform A2 holds the number of rows to calculate B1:B140 column used in calculations (Dependent on what A1 has) C1:C140 column used in calculations (Dependent on what A1 has)
9
3121
by: falcon | last post by:
Is there a way I can do time series calculation, such as a moving average in list comprehension syntax? I'm new to python but it looks like list comprehension's 'head' can only work at a value at a time. I also tried using the reduce function and passed in my list and another function which calculates a moving average outside the list comp. ... but I'm not clear how to do it. Any ideas? Thanks.
33
7534
by: ram.ragu | last post by:
hi i have problem to calculate idle time of cpu and if idle time is more then i have to shut down the system. can anyone tell me the idea to so that please
62
2405
by: Generic Usenet Account | last post by:
A lot of research has been done to prove that the contention that C code is more efficient and more compact than equivalent C++ code is a myth. My posting pertains to a slightly different aspect of this debate. Here are my two questions: 1) Does anyone have any information on comparison of C and C++ software written for the ARM processor? 2) Are there any compiler and CPU dependencies that have to be factored in while debating this...
6
11479
by: Lara1 | last post by:
I'm trying to get certain cells to show a hovering alert message when I click on them. (I don't want an error-message style box to pop up, because I'll eventually want it to show for lots of cells at once.) I recorded a macro to get the code, which I tweaked minimally, and pasted into a clean spreadsheet to test it. It seems to work beautifully. However, when I try to apply the same code within a larger programme, in a working spreadsheet,...
1
1528
by: CoreyReynolds | last post by:
Hey all, Here's the culprit: Sub PopulateRange(Cell_Range As Range) Dim v Dim i As Long Dim j As Long Application.ScreenUpdating = False
0
10164
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9983
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11169
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10694
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9890
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8256
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7431
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6333
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4948
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.