How to print tomorrow's datetime in C#

How to print tomorrow’s datetime in C#:

In this post, we will learn how to print the DateTime of tomorrow in C#. We will learn two different ways to print that in this post.

By using DateTime:

This is the easiest way to do that. DateTime struct provides the current day as Today. We can add days to this by using AddDays method.

If we pass 1 to AddDays, it will add one to today and give us one DateTime for tomorrow.

C# program:

Below is the complete C# program:

using System;
					
public class Program
{
	public static void Main()
	{	
		var today = DateTime.Today;
		
		var tomorrow = today.AddDays(1);
		
		Console.WriteLine("Tomorrow: "+tomorrow.ToString());
	}
}

It will print tomorrow’s date:

Tomorrow: 8/31/2021 12:00:00 AM

How to print the day of tomorrow:

We can use the same program we used above. Once we get a DateTime variable, we can print the day by using the DayOfWeek parameter.

using System;
					
public class Program
{
	public static void Main()
	{	
		var today = DateTime.Today;
		
		var tomorrow = today.AddDays(1);
		
		Console.WriteLine("Tomorrow: "+tomorrow.DayOfWeek.ToString());
	}
}

It will print tomorrow’s day:

Tomorrow: Tuesday

How to use a different format to the datetime:

We can pass a formatter string to the ToString method and it will format the DateTime based on that.

using System;
					
public class Program
{
	public static void Main()
	{	
		var today = DateTime.Today;
		
		var tomorrow = today.AddDays(1);
		
		Console.WriteLine("Tomorrow: "+tomorrow.ToString("dd:MM:yyyy"));
	}
}

It will print one output as like below:

Tomorrow: 31:08:2021

TimeSpan object can be created for one day and we can add this to today to get tomorrow’s DateTime.

using System;
					
public class Program
{
	public static void Main()
	{
		var today = DateTime.Today;
		var oneDay = new TimeSpan(1, 0, 0, 0);
		
		var yesterDay = today + oneDay;
		
		Console.WriteLine("Tomorrow "+yesterDay.ToString());
	}
}

It will print:

Tomorrow 8/31/2021 12:00:00 AM

You might also like: