exit a function betwean a time

  • Thread starter Thread starter Rene A
  • Start date Start date
R

Rene A

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 ?
 
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
 
Rene A said:
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 [C# MVP] schreef:
How could it ever be before 1am *and* after 6am at the same time?


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
 
Try if ((DateTime.Now < DateTime.Parse("01:00:00")) || (DateTime.Now >
DateTime.Parse("06:00:00")))
 
Back
Top