Dates, Times, and Formatting
Date Arithmetic
Add days to a fixed date and compare the result.
Date Arithmetic
DateArithmetic.cs
using System;
using System.Globalization;
class Program
{
static void Main()
{
int addDays = ;
DateTime start = new DateTime(2026, 4, 10);
DateTime due = start.AddDays(addDays);
bool sameMonth = start.Month == due.Month;
string dueText = due.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
Console.WriteLine($"due={dueText}");
Console.WriteLine($"sameMonth={sameMonth}");
}
}
using System;
using System.Globalization;
class Program
{
static void Main()
{
int addDays = ;
DateTime start = new DateTime(2026, 4, 10);
DateTime due = start.AddDays(addDays);
bool sameMonth = start.Month == due.Month;
string dueText = due.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
Console.WriteLine($"due={dueText}");
Console.WriteLine($"sameMonth={sameMonth}");
}
}
using System;
using System.Globalization;
class Program
{
static void Main()
{
int addDays = ;
DateTime start = new DateTime(2026, 4, 10);
DateTime due = start.AddDays(addDays);
bool sameMonth = start.Month == due.Month;
string dueText = due.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
Console.WriteLine($"due={dueText}");
Console.WriteLine($"sameMonth={sameMonth}");
}
}
dates
Date methods return new values, so arithmetic can be assigned and formatted.