getting the day of the week for a given date

15 次查看(过去 30 天)
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