473,396 Members | 2,030 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,396 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 1172
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...

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.