C# DateTime to add days to the current date

The DateTime class in C# provides the AddDays() method to add a specified number of days to a date. This method is commonly used to calculate future dates from the current date or any given date.

Syntax

Following is the syntax for using AddDays() method −

DateTime newDate = dateTime.AddDays(numberOfDays);

Parameters

The AddDays() method accepts the following parameter −

  • numberOfDays − A double value representing the number of days to add. This can be positive (future dates) or negative (past dates).

Return Value

The method returns a new DateTime object with the specified number of days added to the original date. The original DateTime object remains unchanged.

Adding Days to Current Date

To get the current date, use DateTime.Today which returns today's date with time set to midnight. Then use AddDays() to add the desired number of days −

Example

using System;

public class Demo {
    public static void Main() {
        DateTime today = DateTime.Today;
        DateTime futureDate = today.AddDays(10);
        
        Console.WriteLine("Today = {0}", today);
        Console.WriteLine("Add 10 Days = {0}", futureDate);
        Console.WriteLine("Add 30 Days = {0}", today.AddDays(30));
    }
}

The output of the above code is −

Today = 9/11/2018 12:00:00 AM
Add 10 Days = 9/21/2018 12:00:00 AM
Add 30 Days = 10/11/2018 12:00:00 AM

Adding and Subtracting Days

You can add positive values for future dates or negative values for past dates −

Example

using System;

public class DateCalculator {
    public static void Main() {
        DateTime currentDate = DateTime.Now;
        
        Console.WriteLine("Current Date and Time: {0}", currentDate);
        Console.WriteLine("5 days from now: {0}", currentDate.AddDays(5));
        Console.WriteLine("7 days ago: {0}", currentDate.AddDays(-7));
        Console.WriteLine("One week from today: {0}", currentDate.AddDays(7));
    }
}

The output of the above code is −

Current Date and Time: 9/11/2018 2:30:45 PM
5 days from now: 9/16/2018 2:30:45 PM
7 days ago: 9/4/2018 2:30:45 PM
One week from today: 9/18/2018 2:30:45 PM

Working with Specific Dates

The AddDays() method works with any DateTime object, not just the current date −

Example

using System;

public class SpecificDateDemo {
    public static void Main() {
        DateTime specificDate = new DateTime(2023, 12, 25);
        DateTime deliveryDate = specificDate.AddDays(3);
        DateTime orderDate = specificDate.AddDays(-14);
        
        Console.WriteLine("Christmas: {0:yyyy-MM-dd}", specificDate);
        Console.WriteLine("Delivery Date: {0:yyyy-MM-dd}", deliveryDate);
        Console.WriteLine("Order by Date: {0:yyyy-MM-dd}", orderDate);
    }
}

The output of the above code is −

Christmas: 2023-12-25
Delivery Date: 2023-12-28
Order by Date: 2023-12-11

Conclusion

The AddDays() method in C# provides a simple way to calculate dates by adding or subtracting days from any DateTime object. It returns a new DateTime instance without modifying the original date, making it safe for date calculations in your applications.

Updated on: 2026-03-17T07:04:35+05:30

7K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements