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().

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

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

If you wish to look at all C# Programming examples, go to 1000 C# Programs.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.