By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,645 Members | 1,047 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,645 IT Pros & Developers. It's quick & easy.

DateTime.Now falls between two dynamic DateTimes problem

P: n/a
Hi all,
I'm struggling with an elegant way to figure out if DateTime.Now falls
between any Firday @ 6pm and Sunday @ 9pm.

ne1?
~Gordon
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Fri, 06 Feb 2004 18:13:59 -0700, Simple Simon <re***@newsgroup.only>
wrote:
Hi all,
I'm struggling with an elegant way to figure out if DateTime.Now falls
between any Firday @ 6pm and Sunday @ 9pm.

ne1?
~Gordon


Well this would do it.

DateTime d = DateTime.Now;

switch(d.DayOfWeek)
{
case DayOfWeek.Friday:
if(d.Hour >= 18)
return true;
break;
case DayOfWeek.Saturday:
return true;
break; // for good measure
case DayOfWeek.Sunday:
if(d.Hour <= 21)
return true;
break;
default:
break;
}

return false;

Note, code is untested as I have no way to check it right now.

--
The hotmail account will most likely not be read, so please respond only
to the news group.
Nov 15 '05 #2

P: n/a
Many thanks Morten :)

On Sat, 07 Feb 2004 12:51:55 +0100, Morten Wennevik
<Mo************@hotmail.com> wrote:
On Fri, 06 Feb 2004 18:13:59 -0700, Simple Simon <re***@newsgroup.only>
wrote:
Hi all,
I'm struggling with an elegant way to figure out if DateTime.Now falls
between any Firday @ 6pm and Sunday @ 9pm.

ne1?
~Gordon


Well this would do it.

DateTime d = DateTime.Now;

switch(d.DayOfWeek)
{
case DayOfWeek.Friday:
if(d.Hour >= 18)
return true;
break;
case DayOfWeek.Saturday:
return true;
break; // for good measure
case DayOfWeek.Sunday:
if(d.Hour <= 21)
return true;
break;
default:
break;
}

return false;

Note, code is untested as I have no way to check it right now.


Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.