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

Comparing DayOfWeek For A DateTime

Probably a simple question:

I have a function that receives as an argument a DateTime value. One of
the things I want to do is check to see if it's a weekday. So I do the
following (sorry for any wrapping):

if ((dateTimeStart.DayOfWeek != DateTime.DayOfWeek.Saturday) &&
(dateTimeStart.DayOfWeek != DateTime.DayOfWeek.Sunday))
{
...
}

But I get a compile error saying that an object reference is required,
which I assume is referring to the references to Saturday and Sunday,
since dateTimeStart is an object reference. How should I form this so
that I can compare my DateTime's DayOfWeek values with the enumerations?
-David P. Donahue
dd******@ccs.neu.edu
http://www.cyber0ne.com
Jul 11 '06 #1
2 4820
How about just:

if ((dateTimeStart.DayOfWeek != DayOfWeek.Saturday) &&
(dateTimeStart.DayOfWeek != DayOfWeek.Sunday))

David P. Donahue wrote:
Probably a simple question:

I have a function that receives as an argument a DateTime value. One of
the things I want to do is check to see if it's a weekday. So I do the
following (sorry for any wrapping):

if ((dateTimeStart.DayOfWeek != DateTime.DayOfWeek.Saturday) &&
(dateTimeStart.DayOfWeek != DateTime.DayOfWeek.Sunday))
{
...
}

But I get a compile error saying that an object reference is required,
which I assume is referring to the references to Saturday and Sunday,
since dateTimeStart is an object reference. How should I form this so
that I can compare my DateTime's DayOfWeek values with the enumerations?
-David P. Donahue
dd******@ccs.neu.edu
http://www.cyber0ne.com
Jul 11 '06 #2
if ((dateTimeStart.DayOfWeek != DayOfWeek.Saturday) &&
(dateTimeStart.DayOfWeek != DayOfWeek.Sunday))
Sure enough, that's doing the trick. Thanks!
-David P. Donahue
dd******@ccs.neu.edu
http://www.cyber0ne.com
Jul 11 '06 #3

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

Similar topics

3
by: Gerben van Loon | last post by:
Hi there, hope someone can help me on this: DateTime.Now.DayOfWeek is always returning the american day names like "Monday, Saturday". Even when my CurrentCulture is set to my localized culture....
4
by: M | last post by:
Hello, I have code like dt.DayOfWeek.ToString(CultureInfo.CurrentCulture) where dt is a DateTime object. I get something like "Sunday", "Monday", etc... while I'm expecting it to be in...
8
by: simon | last post by:
dateTime sellDate; int16 dayOfWeek; dayOfWeek=sellDate.DayOfWeek I would like to set that monday is the first day of a week and not sunday. Any idea? In VB there is a function, where you...
2
by: Manny Chohan | last post by:
Hi, i have two datetime values in format 11/22/04 9:00 AM and 11/22/04 9:30 AM. How can i compare dates .net c# or if there is any other way such as Javascript. Thanks Manny
0
by: Harry Haller | last post by:
The context is shown below in the getGames() method. I get errors on these lines: dtGames.Rows = (TimeSpan)dtGames.Rows; dtGames.Rows = (DayOfWeek)dtGames.Rows; because the playDate column...
5
by: What-a-Tool | last post by:
Have a group of dynamically created text boxes in a calendar like grid. At the head of each column, the textbox is to contain the day of the week. Now I am using a Select Case statement to...
19
by: Dennis | last post by:
I have a public variable in a class of type color declared as follows: public mycolor as color = color.Empty I want to check to see if the user has specified a color like; if mycolor =...
4
by: richardkreidl | last post by:
How would I check to see if the current time(military format) is greater then 07:30AM and the day of the week is Monday-Friday. Pseudo code: If Current_Time > 07:30AM and Current_Day = Monday...
6
by: Simon Harvey | last post by:
Hi everyone, I need to be able to compare to dates to ensure that one is at least 1 day greater than the other. Im trying to do if(toDate !> fromDate){ // handle }
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.