Groups | Blog | Home
all groups > c# > february 2004 >

c# : DateTime brain teaser


Simple Simon
2/6/2004 11:25:19 PM
Hi all,
I'm struggling with an elegant way to figure out if a DateTime falls
between any Firday @ 6pm and Sunday @ 9pm.

For example:
If i want to fax a message b/w Fri 6pm and Sun 9pm on any given time
on any given day.

ne1?
Miha Markic [MVP C#]
2/7/2004 11:07:54 AM
Hi,

An instance of DateTime has DayOfWeek and Hour properties you might use.
DateTime dt = DateTime.Now()
if (dt.DayOfWeek == DayOfWeek.Friday && dt.Hour >= 18 || dt.DayOfWeek ==
DayOfWeek.Saturday || dt.DayOfWeek ==DayOfWeek.Sunday && dt.Hour <= 21)
{
}
--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

[quoted text, click to view]

Simple Simon
2/7/2004 12:25:44 PM
Many thanks Miha :)

On Sat, 7 Feb 2004 11:07:54 +0100, "Miha Markic [MVP C#]" <miha at
[quoted text, click to view]
AddThis Social Bookmark Button