C#: Calculate the specified day of the week
C# Sharp DateTime: Exercise-9 with Solution
Write a C# Sharp program to calculate what day of the week is 40 days from now.
Sample Solution:-
C# Sharp Code:
using System;
public class Example9
{
// Main method, entry point of the program
public static void Main()
{
// Get the current date and time
System.DateTime today = System.DateTime.Now;
// Display the current date and time
System.Console.WriteLine("Today = " + System.DateTime.Now);
// Define a TimeSpan representing a duration of 40 days
System.TimeSpan duration = new System.TimeSpan(40, 0, 0, 0);
// Add the defined duration (40 days) to the current date
System.DateTime answer = today.Add(duration);
// Display the day of the week for the resulting date
// using the format specifier "{0:dddd}" to get the full day name
System.Console.WriteLine("{0:dddd}", answer);
}
}
Sample Output:
Today = 6/10/2017 11:57:49 AM Thursday
Flowchart :
C# Sharp Code Editor:
Improve this sample solution and post your code through Disqus
Previous: Write a C# Sharp program to retrieve the current date.
Next: Write C# Sharp program to determine the day of the week 40 days after the current date.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/csharp-exercises/datetime/csharp-datetime-exercise-9.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics