KyLim KyLim - 25 days ago 22
ASP.NET (C#) Question

c# check date is weekend or weekday

DayOfWeek today = DateTime.Today.DayOfWeek;
if (today == DayOfWeek.Sunday || today == DayOfWeek.Saturday)
{
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" weekend"');", true);
}
else
{
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" weekday"');", true);
}


From line above i am able to find if today is weekend or weekday

now i want to get the date from user input
i tried this but fail,

my text input format : 2016-10-04 00:00:00.000

string dateInput = dateTextbox.Text;
DayOfWeek today = DateTime.dateInput.DayOfWeek;

Answer

Use DateTime.ParseExact to parse your string into a DateTime

string dateInput = dateTextbox.Text; //"2016-10-04 00:00:00.000"
DateTime dtResult = DateTime.ParseExact(dateInput, "yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture);
DayOfWeek today = dtResult.DayOfWeek;
Comments