473,385 Members | 1,806 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,385 software developers and data experts.

Whats up with this?

JJ
Hi all,

whats wrong with the following code:

DateTime calcDate = new DateTime();

DateTime dDate = DateTime.Now;

if (calcDate.DayOfWeek(dDate) != "Saturday") || (calcDate.DayOfWeek(dDate)
!= "Sunday")

{

}

Thanks,

Jim
Nov 15 '05 #1
5 2056
umm..not sure what you are trying to do...but I'll suggest anyway.

DateTime dateTime = DateTime.Now;

if (dateTime.DayOfWeek == DayOfWeek.Tuesday)
{
Console.WriteLine("Yes it is tuesday");
}

"JJ" <jm***@bellatlantic.net> wrote in message
news:ur*************@TK2MSFTNGP09.phx.gbl...
Hi all,

whats wrong with the following code:

DateTime calcDate = new DateTime();

DateTime dDate = DateTime.Now;

if (calcDate.DayOfWeek(dDate) != "Saturday") || (calcDate.DayOfWeek(dDate)
!= "Sunday")

{

}

Thanks,

Jim

Nov 15 '05 #2
Jim,
whats wrong with the following code:

DateTime calcDate = new DateTime();

DateTime dDate = DateTime.Now;

if (calcDate.DayOfWeek(dDate) != "Saturday") || (calcDate.DayOfWeek(dDate)
!= "Sunday")

{

}

DayOfWeek is a property, you're using it like a method. It returns a
value of the enum type DayOfWeek, not a string. Try it like this

if (dDate.DayOfWeek != DayOfWeek.Saturday ||
dDate.DayOfWeek != DayOfWeek.Sunday)

But then, that code is pretty much useless, since it will always
evaluate to true.

What did you actually want to accomplish?

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 15 '05 #3
JJ
Hi Matt,

Trying to detect in if statement that its not Sat or Sun do the
following code.
So I should use the logical and " && " instead, correct?

Thanks,

JJ
"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
Jim,
whats wrong with the following code:

DateTime calcDate = new DateTime();

DateTime dDate = DateTime.Now;

if (calcDate.DayOfWeek(dDate) != "Saturday") || (calcDate.DayOfWeek(dDate)!= "Sunday")

{

}

DayOfWeek is a property, you're using it like a method. It returns a
value of the enum type DayOfWeek, not a string. Try it like this

if (dDate.DayOfWeek != DayOfWeek.Saturday ||
dDate.DayOfWeek != DayOfWeek.Sunday)

But then, that code is pretty much useless, since it will always
evaluate to true.

What did you actually want to accomplish?

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

Nov 15 '05 #4
JJ
Ah it was the brackets around the expressions that was causing the Invalid
expression.

But at the same time Mattias you were saying that my logic with the if was
going to fail anyway because of using Or correct?

I should be using the and operator && instead in order for the logic to
work, correct?

Thanks,
JJ

"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
Jim,
whats wrong with the following code:

DateTime calcDate = new DateTime();

DateTime dDate = DateTime.Now;

if (calcDate.DayOfWeek(dDate) != "Saturday") || (calcDate.DayOfWeek(dDate)!= "Sunday")

{

}

DayOfWeek is a property, you're using it like a method. It returns a
value of the enum type DayOfWeek, not a string. Try it like this

if (dDate.DayOfWeek != DayOfWeek.Saturday ||
dDate.DayOfWeek != DayOfWeek.Sunday)

But then, that code is pretty much useless, since it will always
evaluate to true.

What did you actually want to accomplish?

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

Nov 15 '05 #5
JJ
Gotcha thanks John !

JJ
"Jon Skeet" <sk***@pobox.com> wrote in message
news:MP************************@news.microsoft.com ...
JJ <jm***@bellatlantic.net> wrote:
Ah it was the brackets around the expressions that was causing the Invalid expression.

But at the same time Mattias you were saying that my logic with the if was going to fail anyway because of using Or correct?


Yes. Look at your code carefully, and think about what it means: you're
specifying that you want something done either if it's not Sunday, or
it's not Saturday. It'll *always* be either not Sunday or not Saturday,
because it can't be both Saturday and Sunday at the same time.
I should be using the and operator && instead in order for the logic to
work, correct?


Either that or rephrase it as (in pseudo-code)

if (! (day==Saturday || day==Sunday) )
{
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too

Nov 15 '05 #6

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

Similar topics

3
by: Chris Geerdink | last post by:
combo with PHP. what is wrong with the Javascript? else { include("mysql.php"); $query1 = mysql_query("INSERT INTO gbook (naam, email, text) VALUES ('".$_POST."', '".$_POST."',...
5
by: kernel.lover | last post by:
hello, I want to know if a fuction say malloc is declared as void *malloc() then whats the significance of void here. Does void * is used when function has the flexibility to return any type of...
2
by: Showjumper | last post by:
Whats the diff between the 2 and when do you use one and not the other?
4
by: David Lozzi | last post by:
OK simple question. Whats the default value for an string() array? sub LoadStuff(byval one as integer, byval two as string, optional byval three() as string = ??) Its driving me nuts! ...
3
by: Amir Shitrit | last post by:
Hi to all. Whats the difference between DynamicInvoke and Invoke methods of the Delegate class? Thanks in advance.
4
by: sophie | last post by:
Whats going on here: Read in a number as a string: scanf("%s", &number); number = 12345, for arguements sake Print it like this its fine:
1
by: '~=_Slawek_=~' | last post by:
$DOW = (jddayofweek(unixtojd(mktime(1, 1, 1, $month, $day, $year)))+6)%7; $DOW= (jddayofweek(juliantojd($month, $day, $year))+6)%7; The results are supposed to be the same, but they are not....
7
by: Mike Barnard | last post by:
It's a simple test... VERY SIMPLE. But... In an external stlyesheet some attributes don't show. With the same styles cut and pasted to the test internally it works as expected. Anyone tell...
2
by: Aaron Gray | last post by:
Whats going on with setAttribute on IE it appears to work on some examples and working code but not on other code that I am writting ? <style> .foo { font-size: 200%; } </style>
7
by: Paulo | last post by:
Hi, what is diference between: File -New Web Site and File -New Project -VB/C# -Web Application ?????? VS 2005
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.