C# Program to Add Two Dates
Posted by Superadmin on August 11 2022 08:41:13

C# Program to Add Two Dates

 

 

This is a C# Program to add two dates.

Problem Description

This C# Program Adds Two Dates.

Problem Solution

Here the new date is found by adding using function AddDays().

Program/Source Code

Here is source code of the C# Program to Add Two Dates . The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/*
 * C# Program to Add Two Dates 
 */
using System;
namespace DateAndTime
{
    class Program
    {
        static int Main()
        {
            DateTime SDate = new DateTime(2010, 10, 7);
            Console.WriteLine("Starting Date : {0}", SDate);
            DateTime EDate = startDate.AddDays(10);
            Console.WriteLine("Ending Date   : {0}\n", EDate);
            Console.ReadLine();
            return 0;
        }
    }
}
Program Explanation

This C# program is used to add two dates. DateTime, is a structure that is available from the System namespace within the base class libraries. This structure has a static method called ‘Now’ that returns the current time. There are a large number of additional data members and methods within the DateTime structure. Here the new date is found by adding using function AddDays().

  
Runtime Test Cases
 
Starting Date : 10/7/2010  12:00:00 AM
Ending Date   : 10/17/2010 12:00:00 AM