%% Sort and Index datetime Array
% Create an array of datetime values and sort them in ascending order, that is, from the earliest to the latest calendar date.

ds = {'2012-12-22';'2063-04-05';'1992-01-12'};
A = datetime(ds,'Format','yyyy-MM-dd')

%

[B,I] = sort(A)

% B lists the sorted dates and I contains the corresponding indices of A.
%
% Access the sorted elements from the original array directly by using the index array I.

A(I)

% Copyright 2015 The MathWorks, Inc.