472,973 Members | 2,367 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

exit a function betwean a time

I want to go out of a function when the local time is

not in 1:00 am / 6:00 am

im using the folowing code :

if ((DateTime.Now < DateTime.Parse("01:00:00")) && (DateTime.Now >
DateTime.Parse("06:00:00")))
{
Return;
}

But it dont work, anyone a tip /id ?
Sep 11 '08 #1
4 1164
DateTime.Now will include today's date, where-as Parse("01:00:00")
won't. You might consider using .Now.TimeOfDay and TimeSpan.Parse?

Marc
Sep 11 '08 #2
Rene A <Rene@nospam-Nospamwrote:
I want to go out of a function when the local time is

not in 1:00 am / 6:00 am

im using the folowing code :

if ((DateTime.Now < DateTime.Parse("01:00:00")) && (DateTime.Now >
DateTime.Parse("06:00:00")))
{
Return;
}
How could it ever be before 1am *and* after 6am at the same time?
But it dont work, anyone a tip /id ?
Here's a simpler version:

DateTime now = DateTime.Now;
if (now.Hour < 1 || now.Hour >= 6)
{
return;
}

(That will still exit if it's exactly 6am, but I suspect that's
probably okay for you.)

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Sep 11 '08 #3
Jon Skeet [C# MVP] schreef:
Rene A <Rene@nospam-Nospamwrote:
>I want to go out of a function when the local time is

not in 1:00 am / 6:00 am

im using the folowing code :

if ((DateTime.Now < DateTime.Parse("01:00:00")) && (DateTime.Now >
DateTime.Parse("06:00:00")))
{
Return;
}

How could it ever be before 1am *and* after 6am at the same time?
>But it dont work, anyone a tip /id ?

Here's a simpler version:

DateTime now = DateTime.Now;
if (now.Hour < 1 || now.Hour >= 6)
{
return;
}

(That will still exit if it's exactly 6am, but I suspect that's
probably okay for you.)

Marc && Jon thanks for pointing me in the right direction,
now i can finish the National Bank security project ;-)

Groetjes Rene
Sep 11 '08 #4
Try if ((DateTime.Now < DateTime.Parse("01:00:00")) || (DateTime.Now >
DateTime.Parse("06:00:00")))

"Rene A" <Rene@nospam-Nospamwrote in message
news:48*********************@news.xs4all.nl...
I want to go out of a function when the local time is

not in 1:00 am / 6:00 am

im using the folowing code :

if ((DateTime.Now < DateTime.Parse("01:00:00")) && (DateTime.Now >
DateTime.Parse("06:00:00")))
{
Return;
}

But it dont work, anyone a tip /id ?

Sep 13 '08 #5

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

Similar topics

1
by: deepak | last post by:
I am using the code below to implement 1 time entry and exit popup. The entry popup works fine, but the exit popup opens even if you browse from one page to the other on the same site. I want it to...
7
by: deko | last post by:
I have a function with a number of long loops. While the function is running, I want to be able to click a Stop button and exit the function as quickly as possible. The abbreviated code looks...
8
by: drose0927 | last post by:
Please help! I can't get my program to exit if the user hits the Escape button: When I tried exit(EXIT_SUCCESS), it wouldn't compile and gave me this error: Parse Error, expecting `'}''...
6
by: orekin | last post by:
Hi There I have been trying to come to grips with Application.Run(), Application.Exit() and the Message Pump and I would really appreciate some feedback on the following questions .. There are...
13
by: PeterZ | last post by:
Hi, Back to basics! My understanding is that the only way to exit a For-Next loop prematurely is with the 'break' keyword. How are you supposed to do that if you're inside a Switch...
20
by: lovecreatesbeauty | last post by:
Hello experts, Is the following code snippet legal? If it is, how can exit() do the keyword return a favor and give a return value to the main function? Can a function call (or only this...
7
by: Peter | last post by:
When compiling the following code to study the execv() system call, I get the compilation error for exit() shown below. I'm using ssh from home to access my university Unix console. I was...
11
by: =?Utf-8?B?U3RldmVEQjE=?= | last post by:
Hi all. I'm using VS 2008 Express C++. I created a console application back in 1999, and updated it for VC++ 6.0 in 2001. I've updated again this past month, and have found enough differences...
39
by: mathieu | last post by:
Hi there, I am trying to reuse a piece of code that was designed as an application. The code is covered with 'exit' calls. I would like to reuse it as a library. For that I renamed the 'main'...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.