Spliting a date to day, month and year
4 次查看(过去 30 天)
显示 更早的评论
Hello,
Suppose I have a date in this form only : 14/2/1923 or 8/2/1923 (not 14/02/1923 or 08/02/1923)
How can I split it to day, month and year? there are no zeros at all in the date.
Thank's!
0 个评论
采纳的回答
José-Luis
2013-5-16
myDate = '4/2/1923';
mySplitDate = regexp(myDate,'/','split');
myDatevec = cellfun(@(x) str2double(x),mySplitDate)
0 个评论
更多回答(2 个)
Andrei Bobrov
2013-5-16
de = {'14/2/1923', '8/2/1923'};
ymd = datevec(de,'dd/mm/yyyy');
out = ymd(:,3:-1:1);
0 个评论
Jan
2013-5-16
Faster:
S = '14/2/1923';
D = sscanf(S, '%d/%d/%d', 3);
Or for cell strings:
S = {'14/2/1923', '23/12/1924'};
C = sprintf('%s*', S{:});
D = sscanf(C, '%d/%d/%d*', [3, length(S)]);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!