471,325 Members | 1,434 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 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 1128
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by drose0927 | last post: by
20 posts views Thread by lovecreatesbeauty | last post: by
7 posts views Thread by Peter | last post: by
11 posts views Thread by =?Utf-8?B?U3RldmVEQjE=?= | last post: by
39 posts views Thread by mathieu | last post: by
reply views Thread by rosydwin | last post: by

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.