DateTime

  • Thread starter Thread starter JD
  • Start date Start date
J

JD

Hi
I'm trying to find out how to display a message on a date. I know how to do
it in C++, but now i'm learning C# i would also like to do it in this
language. This is the code i'm using:

using System; // has all the date/time stuff

class myApp

{

public static void Main()

{

DateTime CurrTime = DateTime.Today;

Console.WriteLine(CurrTime.Day);

Console.WriteLine(CurrTime.Month);





if (CurrTime.Day = "27" + CurrTime.Month ="10")

{

Console.WriteLine("Birthday");

}

else

{

Console.WriteLine("Not Birthday");

}

Console.ReadLine();

}

}



This code doesn't seem to work, any advice?

thanks in advance.
 
JD You need to learn some more elementary stuff!
Try:
if (CurrTime.Day == "27" && CurrTime.Month == "10")
 
JD You need to learn some more elementary stuff!
Try:
if (CurrTime.Day == "27" && CurrTime.Month == "10")

Elementary, like knowing the difference between an integer and a string?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A watched clock never boils.
 
A DateTime.Day is an integer, not a string.

Same thing with a DateTime.Month.

Integers are numbers, and strings are characters. If you come from a VB
background, you're going to have to get used to handling the difference for
yourself. VB tends not to bother the developer with this sort of detail,
unless one turns Option Strict ON, which is an invaluable thing to do with
..Net, which is by nature strongly typed.

Also, the "+" operator is used to concatenate strings. It can also be used
for addition of numbers. The logical AND operator is "&&".

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A watched clock never boils.
 
BTW, if you're just learning, have patience, and be persistent. It *does*
get easier with time, and is very rewarding!

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A watched clock never boils.
 
Back
Top