473,396 Members | 1,726 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.

DateTime brain teaser

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?
~Gordon
Nov 15 '05 #1
2 1703
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

"Simple Simon" <re***@newsgroup.only> wrote in message
news:92********************************@4ax.com...
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?
~Gordon

Nov 15 '05 #2
Many thanks Miha :)

On Sat, 7 Feb 2004 11:07:54 +0100, "Miha Markic [MVP C#]" <miha at
rthand com> wrote:
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)
{
}


Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: brendan | last post by:
here's a brain teaser for someone with more skills or at least more lateral thinking capability than me - done my nut over this one... have written a list manager in PHP which a) posts out new...
4
by: Max M | last post by:
# -*- coding: latin-1 -*- """ I am currently using the datetime package, but I find that the design is oddly asymmetric. I would like to know why. Or perhaps I have misunderstood how it...
2
by: Kenneth P | last post by:
Hi, I'm trying to use MySql 4.1 db instead of MSSql2k and am having problems with the DateTime in the db. In mysqladmtools 1.0.19 I'm recommended to use 0000-00-00 00:00:00 as the default...
15
by: Chung Leong | last post by:
Here's a little brain teaser distilled from a bug that took me a rather long time to figure out. The two functions in the example below behave differently. The difference is easy to spot, of...
7
by: Mark A | last post by:
If server 01 running HADR in the primary role crashes, and the DBA does a HADR takeover by force on the 02 server to switch roles, then the 02 server is now the primary. What happens when the...
3
by: datagal | last post by:
I have a requirement (motivated by a SOX thing) that is just giving me fits. I know it should be easy and I'm probably overthinking it, but I just can seem to find the best way to get where I need...
3
by: Joachim Klassen | last post by:
Hi all, if I accidentally use a TAKEOVER command with BY FORCE clause while primary and standby are in peer state I'll end up with two primary's (at least with FP10 and Windows). Is this works ...
4
by: Greg Collins [Microsoft MVP] | last post by:
Will DateTime.Now.ToString("s") ALWAYS return the same formatting (i.e. the sortable XML Schema style formatting) regardless of what culture the operating system is set to? I've done limited...
2
RedSon
by: RedSon | last post by:
Given a directed graph of k-nodes such that the last node creates a cycle with any other node determine which node the last node's edge points to using the minimum amount of resources and without...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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.