w3resource logo


C# Sharp Programming Exercises

C# Sharp Exercises: Compute what day was yesterday

Secondary Nav

C# Sharp DateTime : Exercise-44 with Solution

Write a program in C# Sharp to compute what day was yesterday.

Expected Output :

Today is : 17/09/2016
 The Yesterday was : 16/09/2016

C# Sharp Code:

using System;

class dttimeex44
{
    static void Main()
    {
	Console.Write("\n\n Compute what day was  Yesterday :\n");
	Console.Write("--------------------------------------\n");
	Console.WriteLine(" Today is : {0}", DateTime.Today.ToString("dd/MM/yyyy"));
	DateTime yd = GetYesterday();
	Console.WriteLine(" The Yesterday was : {0} \n", yd.ToString("dd/MM/yyyy"));
    }
    static DateTime GetYesterday()
    {
	return DateTime.Today.AddDays(-1);
    }
}

C# Sharp Practice online:

using System;

class dttimeex44
{
    static void Main()
    {
	Console.Write("\n\n Compute what day was  Yesterday :\n");
	Console.Write("--------------------------------------\n");
	Console.WriteLine(" Today is : {0}", DateTime.Today.ToString("dd/MM/yyyy"));
	DateTime yd = GetYesterday();
	Console.WriteLine(" The Yesterday was : {0} \n", yd.ToString("dd/MM/yyyy"));
    }
    static DateTime GetYesterday()
    {
	return DateTime.Today.AddDays(-1);
    }
}

Improve this sample solution and post your code through Disqus.



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

PHP: Loop

JavaScript: Delete duplicates in an array

Oracle: Round the number