This code is a simplified version of what I'm trying to do:
this.dateValue = "8/12/2005";
return DateTime.dateValue.DayOfWeek.ToString();
I want to use my dateValue in stead of 'NOW'
This code is a simplified version of what I'm trying to do:
this.dateValue = "8/12/2005";
return DateTime.dateValue.DayOfWeek.ToString();
I want to use my dateValue in stead of 'NOW'
this.dateValue = "8/12/2005";
DateTime dt;
// assuming the expected date is the 8th of Dec 2005, otherwise use m/d/yyyy
if (DateTime.TryParseExact(this.dateValue, "d/m/yyyy", CulterInfo.InvariantCulture,
DateTimeStyles.None, out dt))
{
return dt.DayOfWeek.ToString();
}
else
{
return null;
}
The DateTime.Now
property returns a DateTime, DayOfWeek is a property of DateTime so you can simply do
return DateTime.Now.DayOfWeek.ToString();
To get the text version of the current Day of the Week
If you want to reverse this you can parse a new DateTime from the string.
return DateTime.Parse("8/12/2005").DayOfWeek.ToString();
Watch our for strings which can't be parsed. You may want to look into the TryParse method.