# Blogs Hub

### by Sumit Chourasia | Jun 12, 2020 | Category :coding | Tags : डेटा-संरचनाleetcodealgorithmc-sharparray

#### Day of the Week - Array - Easy - LeetCode - मिनी टीवी

Given a date, return the corresponding day of the week for that date.

The input is given as three integers representing the day, month and year respectively.

Return the answer as one of the following values {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}.

Example 1:

Input: day = 31, month = 8, year = 2019

Output: "Saturday"

Example 2:

Input: day = 18, month = 7, year = 1999

Output: "Sunday"

Example 3:

Input: day = 15, month = 8, year = 1993

Output: "Sunday"

Constraints:

The given dates are valid dates between the years 1971 and 2100.

Solution:

``````using System;
using System.Collections.Generic;
using System.Text;

{
public class DayOfTheWeekSoln
{
public string DayOfTheWeek(int day, int month, int year)
{
var date = new DateTime(year, month, day);
return date.DayOfWeek.ToString();
}
}
}
``````

Time Complexity: O(1)

Space Complexity: O(1)

Unit Tests:

``````using LeetCode.AskGif.Easy.Array;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Text;

namespace CodingUnitTest.Easy.Array
{
[TestClass]
public class DayOfTheWeekSolnTests
{
[TestMethod]
public void DayOfTheWeekSoln_First()
{
var day = 31;
var month = 8;
var year = 2019;

var output = "Saturday";

var res = new DayOfTheWeekSoln().DayOfTheWeek(day, month, year);

Assert.AreEqual(output, res);
}

[TestMethod]
public void DayOfTheWeekSoln_Second()
{
var day = 18;
var month = 7;
var year = 1999;

var output = "Sunday";

var res = new DayOfTheWeekSoln().DayOfTheWeek(day, month, year);

Assert.AreEqual(output, res);
}

[TestMethod]
public void DayOfTheWeekSoln_Third()
{
var day = 15;
var month = 8;
var year = 1993;

var output = "Sunday";

var res = new DayOfTheWeekSoln().DayOfTheWeek(day, month, year);

Assert.AreEqual(output, res);
}
}
}
``````

Contributed By: Sumit Chourasia
Contributed By: Sumit Chourasia
Contributed By: Sumit Chourasia
Contributed By: Sumit Chourasia