Days until next birthday
-
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 } }
-
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 } }
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
-
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
-
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(); } }
-
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(); } }
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
-
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(); } }
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
-
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 } }
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.