Reputation: 77
I have
num4 = xlsread('dat.xlsx', 1, 'A:B');
dnum4=datetime(num4(:,1),1,1) + caldays(num4(:,2));
dnum4=
16-Jul-2008
18-Jul-2008
06-Aug-2008
08-Aug-2008
13-Aug-2008
15-Aug-2008
20-Aug-2008
22-Aug-2008
30-Oct-2008
I want to change the outputs from dd-mmm-yyyy
to yyyy-mm-dd
.
How to do that?
Upvotes: 1
Views: 3014
Reputation: 12214
If you look at the documentation you'll see that datetime
objects have a Format
property that controls the display format:
>> t = datetime('now','TimeZone','local','Format','d-MMM-y HH:mm:ss Z')
t =
datetime
25-May-2017 10:26:46 -0400
>> t.Format = 'yyyy-MM-dd'
t =
datetime
2017-05-25
Upvotes: 4
Reputation: 2426
One way is to convert to datenum, then back to datestr:
newFmt = datestr(datenum(dnum4, 'dd-mmm-yyyy'), 'yyyy-mm-dd')
Upvotes: -1