473,320 Members | 2,110 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,320 software developers and data experts.

DateTime.Now falls between two dynamic DateTimes problem

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
2 1289
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: sho_nuff | last post by:
Hello all, I have several DateTime objects and i want to get the average of all of them. What would be the easiest way to do this? Thanks SN
14
by: ChrisM | last post by:
Could anyone please tell me the difference between these 2 lines: myDate = DateTime.Now; and myDate = DateTime.Parse(DateTime.Now.ToString("dd/MM/yyyy")); Seeing as later on in the...
3
by: Tim Cowan | last post by:
Hi, In my application I need to compare whether one time is greater than another. What I am doing right now is taking the current datetime, formatting as string without the time element, and...
2
by: Rob Roberts | last post by:
I have a GridView that is bound to a collection of DateTimes (i.e. - Collection<DateTime>). I have a BoundField in the GridView, and its DataField is set to the DateTime's Date property, and the...
10
by: David P. Donahue | last post by:
Can anyone think of an easy way to take two DateTime values and calculate, with double precision, how many semi-monthly (the first and the fifteenth) pay periods occur between them? I started...
3
by: C Villalba | last post by:
Birth Date and a Purchase Date aata is being stored in sql. This information is retrieved across time zones through a .Net Web Service. When the data is viewed in a .Net client application these...
3
by: Zachary Turner | last post by:
Hello, I have a situation where I would like to perform custom serialization and deserialization of an existing .NET framework object (specifically, System.DateTime). Is there a common paradigm...
2
by: BLUE | last post by:
I want to store and retrieve datetime in ISO 8601 format: '2007-06-02T16:12:08.123-04:34' or '2007-06-02T16:12:08.123Z' When I insert a datetime with SQL Server Management Studio and then I...
0
yasirmturk
by: yasirmturk | last post by:
Standard Date and Time Functions The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.