Hello every one, I am new to programming, as well as the C# language, so I would appreciate any help that you will offer. Thank you in advance.
I need to create a variable to hold time from one month, day to another month, day.
Example
TimeSpan AQUARIUS = ( March 21 "to" April 19);
How can this be done.
AlanPosted Jul 8, 2008, 2:03 PM
Try this:
using System;
class Program
{
static void Main()
{
string ARIES = "( March 21 \"to\" April 19)";
TimeSpan ts = GetTimeSpan(ARIES);
Console.WriteLine(ts.Days); // 30 days (inclusive)
Console.ReadLine();
}
static TimeSpan GetTimeSpan(string span)
{
string temp = span.Substring(2, span.Length - 3);
string[] array = temp.Split(' ');
DateTime dt1 = DateTime.Parse(array[1] + " " + array[0]);
DateTime dt2 = DateTime.Parse(array[4] + " " + array[3]);
if (dt2 < dt1) dt2 = dt2.AddYears(1);
return dt2.AddDays(1) - dt1;
}
}