DateTime

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JD

    DateTime

    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.WriteLi ne(CurrTime.Day );

    Console.WriteLi ne(CurrTime.Mon th);





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

    {

    Console.WriteLi ne("Birthday") ;

    }

    else

    {

    Console.WriteLi ne("Not Birthday");

    }

    Console.ReadLin e();

    }

    }



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

    thanks in advance.


  • quilkin

    #2
    RE: DateTime

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

    "JD" wrote:
    [color=blue]
    > 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.WriteLi ne(CurrTime.Day );
    >
    > Console.WriteLi ne(CurrTime.Mon th);
    >
    >
    >
    >
    >
    > if (CurrTime.Day = "27" + CurrTime.Month ="10")
    >
    > {
    >
    > Console.WriteLi ne("Birthday") ;
    >
    > }
    >
    > else
    >
    > {
    >
    > Console.WriteLi ne("Not Birthday");
    >
    > }
    >
    > Console.ReadLin e();
    >
    > }
    >
    > }
    >
    >
    >
    > This code doesn't seem to work, any advice?
    >
    > thanks in advance.
    >
    >
    >[/color]

    Comment

    • Kevin Spencer

      #3
      Re: DateTime

      > JD You need to learn some more elementary stuff![color=blue]
      > Try:
      > if (CurrTime.Day == "27" && CurrTime.Month == "10")[/color]

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

      --
      HTH,

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

      "quilkin" <quilkin@discus sions.microsoft .com> wrote in message
      news:2D0545DB-2DDE-4C49-A939-05D5FEE56712@mi crosoft.com...[color=blue]
      > JD You need to learn some more elementary stuff!
      > Try:
      > if (CurrTime.Day == "27" && CurrTime.Month == "10")
      >
      > "JD" wrote:
      >[color=green]
      >> 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.WriteLi ne(CurrTime.Day );
      >>
      >> Console.WriteLi ne(CurrTime.Mon th);
      >>
      >>
      >>
      >>
      >>
      >> if (CurrTime.Day = "27" + CurrTime.Month ="10")
      >>
      >> {
      >>
      >> Console.WriteLi ne("Birthday") ;
      >>
      >> }
      >>
      >> else
      >>
      >> {
      >>
      >> Console.WriteLi ne("Not Birthday");
      >>
      >> }
      >>
      >> Console.ReadLin e();
      >>
      >> }
      >>
      >> }
      >>
      >>
      >>
      >> This code doesn't seem to work, any advice?
      >>
      >> thanks in advance.
      >>
      >>
      >>[/color][/color]


      Comment

      • Kevin Spencer

        #4
        Re: DateTime

        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.

        "JD" <jd@billgates.c om> wrote in message
        news:dk2s02$ene $1$8300dec7@new s.demon.co.uk.. .[color=blue]
        > 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.WriteLi ne(CurrTime.Day );
        >
        > Console.WriteLi ne(CurrTime.Mon th);
        >
        >
        >
        >
        >
        > if (CurrTime.Day = "27" + CurrTime.Month ="10")
        >
        > {
        >
        > Console.WriteLi ne("Birthday") ;
        >
        > }
        >
        > else
        >
        > {
        >
        > Console.WriteLi ne("Not Birthday");
        >
        > }
        >
        > Console.ReadLin e();
        >
        > }
        >
        > }
        >
        >
        >
        > This code doesn't seem to work, any advice?
        >
        > thanks in advance.
        >
        >[/color]


        Comment

        • Kevin Spencer

          #5
          Re: DateTime

          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.

          "JD" <jd@billgates.c om> wrote in message
          news:dk2s02$ene $1$8300dec7@new s.demon.co.uk.. .[color=blue]
          > 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.WriteLi ne(CurrTime.Day );
          >
          > Console.WriteLi ne(CurrTime.Mon th);
          >
          >
          >
          >
          >
          > if (CurrTime.Day = "27" + CurrTime.Month ="10")
          >
          > {
          >
          > Console.WriteLi ne("Birthday") ;
          >
          > }
          >
          > else
          >
          > {
          >
          > Console.WriteLi ne("Not Birthday");
          >
          > }
          >
          > Console.ReadLin e();
          >
          > }
          >
          > }
          >
          >
          >
          > This code doesn't seem to work, any advice?
          >
          > thanks in advance.
          >
          >[/color]


          Comment

          Working...