Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Days until next birthday

Days until next birthday

Scheduled Pinned Locked Moved C#
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DFlat4Now
    wrote on last edited by
    #1

    I need just a simple console program to tell how many days and hours (minutes if possible) until this persons next birthday. He was born on July 26th 1983 at 8:00 pm. I'm really new at this and I wanted to give him a small exe (console program) for his birthday. This is all I oould come up with so far: using System; class myApp { public static void Main() { DateTime CurrTime = DateTime.Now; DateTime JimBDay = DateTime.Compare(CurrTime, "08/01/2008"); Console.WriteLine("Jim's Birthdate: ", JimBDay); Console.WriteLine("Jim's Birthday is July 26th at 8:00 pm"); Console.WriteLine("{0:F}", CurrTime); // Need some code to say there are this many days and this many hours until your next birthday (minutes if possible). Console.Read(); // wait } }

    R G 2 Replies Last reply
    0
    • D DFlat4Now

      I need just a simple console program to tell how many days and hours (minutes if possible) until this persons next birthday. He was born on July 26th 1983 at 8:00 pm. I'm really new at this and I wanted to give him a small exe (console program) for his birthday. This is all I oould come up with so far: using System; class myApp { public static void Main() { DateTime CurrTime = DateTime.Now; DateTime JimBDay = DateTime.Compare(CurrTime, "08/01/2008"); Console.WriteLine("Jim's Birthdate: ", JimBDay); Console.WriteLine("Jim's Birthday is July 26th at 8:00 pm"); Console.WriteLine("{0:F}", CurrTime); // Need some code to say there are this many days and this many hours until your next birthday (minutes if possible). Console.Read(); // wait } }

      R Offline
      R Offline
      Reza Raad
      wrote on last edited by
      #2

      you can use subtract Method to get days and hours and minutes and seconds difference between two date. see this code:

      DateTime CurrTime = DateTime.Now;
      DateTime JimBDay = new DateTime(1983,7,26,20,0,0);

              TimeSpan span= CurrTime.Subtract(JimBDay);
      

      now span has days and hours and minutes and seconds difference between jim birthday and now.

      Human knowledge belongs to the world

      D 1 Reply Last reply
      0
      • R Reza Raad

        you can use subtract Method to get days and hours and minutes and seconds difference between two date. see this code:

        DateTime CurrTime = DateTime.Now;
        DateTime JimBDay = new DateTime(1983,7,26,20,0,0);

                TimeSpan span= CurrTime.Subtract(JimBDay);
        

        now span has days and hours and minutes and seconds difference between jim birthday and now.

        Human knowledge belongs to the world

        D Offline
        D Offline
        DFlat4Now
        wrote on last edited by
        #3

        Many thanks!

        D 1 Reply Last reply
        0
        • D DFlat4Now

          Many thanks!

          D Offline
          D Offline
          DFlat4Now
          wrote on last edited by
          #4

          JimBDay does not show up on Console.WriteLine("Jim's Birthdate is... ", JimBDay); it just says "Jim's Birthday is..." and "span" shows as 9132.03:46:30.4287493 / How can I format this to say... This many months... This many days... This many hours... and This many minuts until your next birthday? using System; class myApp { public static void Main() { DateTime CurrTime = DateTime.Now; Console.WriteLine("Right now the date and time are: {0:F}", CurrTime); DateTime JimBDay = new DateTime(1983, 7, 26, 20, 0, 0); Console.WriteLine("Jim's Birthdate is... ", JimBDay); TimeSpan span = CurrTime.Subtract(JimBDay); Console.WriteLine(span); Console.Read(); } }

          P R 2 Replies Last reply
          0
          • D DFlat4Now

            JimBDay does not show up on Console.WriteLine("Jim's Birthdate is... ", JimBDay); it just says "Jim's Birthday is..." and "span" shows as 9132.03:46:30.4287493 / How can I format this to say... This many months... This many days... This many hours... and This many minuts until your next birthday? using System; class myApp { public static void Main() { DateTime CurrTime = DateTime.Now; Console.WriteLine("Right now the date and time are: {0:F}", CurrTime); DateTime JimBDay = new DateTime(1983, 7, 26, 20, 0, 0); Console.WriteLine("Jim's Birthdate is... ", JimBDay); TimeSpan span = CurrTime.Subtract(JimBDay); Console.WriteLine(span); Console.Read(); } }

            P Offline
            P Offline
            Paul Conrad
            wrote on last edited by
            #5

            You'll have to pick apart the pieces from the span. There's Days, Minutes, and other properties to investigate.

            "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

            1 Reply Last reply
            0
            • D DFlat4Now

              JimBDay does not show up on Console.WriteLine("Jim's Birthdate is... ", JimBDay); it just says "Jim's Birthday is..." and "span" shows as 9132.03:46:30.4287493 / How can I format this to say... This many months... This many days... This many hours... and This many minuts until your next birthday? using System; class myApp { public static void Main() { DateTime CurrTime = DateTime.Now; Console.WriteLine("Right now the date and time are: {0:F}", CurrTime); DateTime JimBDay = new DateTime(1983, 7, 26, 20, 0, 0); Console.WriteLine("Jim's Birthdate is... ", JimBDay); TimeSpan span = CurrTime.Subtract(JimBDay); Console.WriteLine(span); Console.Read(); } }

              R Offline
              R Offline
              Reza Raad
              wrote on last edited by
              #6

              try these properties:

              Console.WriteLine(span.Days.ToString());
              Console.WriteLine(span.Hours.ToString());
              Console.WriteLine(span.Minutes.ToString());
              Console.WriteLine(span.Seconds.ToString());
              Console.WriteLine(span.Milliseconds.ToString());

              Human knowledge belongs to the world

              1 Reply Last reply
              0
              • D DFlat4Now

                I need just a simple console program to tell how many days and hours (minutes if possible) until this persons next birthday. He was born on July 26th 1983 at 8:00 pm. I'm really new at this and I wanted to give him a small exe (console program) for his birthday. This is all I oould come up with so far: using System; class myApp { public static void Main() { DateTime CurrTime = DateTime.Now; DateTime JimBDay = DateTime.Compare(CurrTime, "08/01/2008"); Console.WriteLine("Jim's Birthdate: ", JimBDay); Console.WriteLine("Jim's Birthday is July 26th at 8:00 pm"); Console.WriteLine("{0:F}", CurrTime); // Need some code to say there are this many days and this many hours until your next birthday (minutes if possible). Console.Read(); // wait } }

                G Offline
                G Offline
                Guffa
                wrote on last edited by
                #7

                First you need to find the next birthday. Create a DateTime value for the birthday this year (from the current year and the month and day from the birthday). If it has passed, add a year to the value. Now you just subtract the current date from the value, and you get a TimeSpan that holds the time difference.

                Despite everything, the person most likely to be fooling you next is yourself.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups