MATLAB: Help writing a script that tells the day of the week

datetimescript

I need help writing a code that tells me the day of the week as well as the number of the day relative to the year. Ex: input form month/day/year: xx/xx/xxxx output should say something like: The date 08/31/2011 is the 243 day of the year and is a wednesday.
I have tried so many different things from Mathworks with no luck.

Best Answer

One way (not using datetime, since not everyone may have it):
InpStr = '08/31/2011';
YrStart = datenum(InpStr(end-3:end), 'yyyy');
dtnm = datenum(InpStr, 'mm/dd/yyyy');
[DayOfWkNum,DayOfWkStr] = weekday(dtnm,'long');
fprintf(1, '\n\tThe date %s is the %d day of the year and is a %s\n', InpStr, dtnm-YrStart+1, DayOfWkStr)
The date 08/31/2011 is the 243 day of the year and is a Wednesday