필터 지우기
필터 지우기

getting the day of the week for a given date

조회 수: 15 (최근 30일)
OLUBUKOLA ogunsola
OLUBUKOLA ogunsola 2016년 6월 8일
댓글: Steven Lord 2021년 12월 9일
As today is Wednesday with date June 8, 2016. how can i write a code to get the day of given dates: like what day is Nov 29 I'm trying to create a struct with date
day
month
with month and date as input
  댓글 수: 1
paul Erameh
paul Erameh 2021년 12월 9일
i actually need something like this that can work for any year. meaning i would input a date and it would tell me the day. please help me out.

댓글을 달려면 로그인하십시오.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 6월 8일
편집: Azzi Abdelmalek 2016년 6월 8일
d='jun-08-2016'
d=datestr(d,'mmm-dd-yyyy')
datestr(d,'mmm-ddd-yyyy')

추가 답변 (1개)

Stephen23
Stephen23 2016년 6월 8일
편집: Stephen23 2016년 6월 8일
>> datestr(datenum('June 8, 2016','mmmm dd, yy'),'dddd')
ans =
Wednesday
>> datestr(datenum('November 29, 2016','mmmm dd, yy'),'dddd')
ans =
Tuesday
But a much better option would be to store the date as date vectors, which makes the processing much simpler:
>> datestr([2016,06,08,0,0,0],'dddd')
ans =
Wednesday
>> datestr([2016,11,29,0,0,0],'dddd')
ans =
Tuesday
  댓글 수: 9
paul Erameh
paul Erameh 2021년 12월 9일
i actually need something like this that can work for any year. meaning i would input a date and it would tell me the day. please help me out.
Steven Lord
Steven Lord 2021년 12월 9일
Use the day function for datetime arrays.
dt = datetime('today')
dt = datetime
09-Dec-2021
d = day(dt, 'short')
d = 1×1 cell array
{'Thu'}

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by