Spliting a date to day, month and year

4 vues (au cours des 30 derniers jours)
googo
googo le 16 Mai 2013
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!

Réponse acceptée

José-Luis
José-Luis le 16 Mai 2013
myDate = '4/2/1923';
mySplitDate = regexp(myDate,'/','split');
myDatevec = cellfun(@(x) str2double(x),mySplitDate)

Plus de réponses (2)

Andrei Bobrov
Andrei Bobrov le 16 Mai 2013
de = {'14/2/1923', '8/2/1923'};
ymd = datevec(de,'dd/mm/yyyy');
out = ymd(:,3:-1:1);

Jan
Jan le 16 Mai 2013
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)]);

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by