Creating String Array Between Two Dates

16 ビュー (過去 30 日間)
Michael Basford
Michael Basford 2019 年 11 月 16 日
回答済み: Star Strider 2019 年 11 月 16 日
I'm trying to create a 1xn array of strings of dates between two dates, incrementing by one day, in the form:
DateArr = [16-Nov-2019, 17-Nov-2019, 18-Nov-2019, ...]
However, I cannot seem to get my code to work, it simply creates an empty 1x0 array instead. Where am I going wrong? I am converting to datetime so that the dates are in scalar form for the DayArr generation, but it is not at all how I expected to create the two scalars (as arrays).
EndDate = '03-feb-2019';
DateVec = datetime(datevec(date));
EndDateVec = datetime(datevec(EndDate));
DayArr = DateVec:EndDateVec;

回答 (1 件)

Star Strider
Star Strider 2019 年 11 月 16 日
Try this:
date = '01-jan-2019';
EndDate = '03-feb-2019';
DateVec = datetime(date);
EndDateVec = datetime(EndDate);
DayArr = DateVec:days(1):EndDateVec;
Choose your own day for ‘date’.

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by