There is no method of subtraction, but just use a mathematical trick with the method AddDays()
:
using System;
namespace TesteData {
public class Program {
public static void Main(string[] args) {
var dataAtual = DateTime.Now.Date;
var qtdDias = 5;
var novaData = dataAtual.AddDays(-qtdDias);
Console.WriteLine(novaData);
}
}
}
Behold working ideone. And in the .NET Fiddle. Also put on the Github for future reference.
To subtract a particular time interval from the Current instance, call the method that adds that time interval to the Current date, and Supply a Negative value as the method argument. For example, to subtract two months from the Current date, call the AddMonths(Int32)
method with a value of -2.
Documentation.