Hi
Does anyone know how to convert yymmdd to dd/mm/yyyy? I have dates is given in the yymmdd format, such as 750525,780215,.....which mean year 1975, month-5, day-25 or year 1978, month-2,day-15. I wanted to convert the date in the form dd/mm/yyyy which is as 25/05/1975, 15/02/1978.
How I can do it?
Thanks a lot!

 채택된 답변

Jos (10584)
Jos (10584) 2016년 6월 6일

2 개 추천

A = {'750525','780215'}
B = cellstr(datestr(datenum(A,'yymmdd'),'dd/mm/yyyy'))

댓글 수: 5

davit petraasya
davit petraasya 2016년 6월 6일
Thanks Jos for your answer. When I run it I am getting error message saying:
The input to DATENUM was not an array of strings. (I have date is given in excel as 750525,780215,... in my colomn) What would be problem?
Jos (10584)
Jos (10584) 2016년 6월 6일
How do you get them into matlab? You should convert them first to a cell array of strings for datenum to work properly.
davit petraasya
davit petraasya 2016년 6월 6일
My matlab reading dates 750525,780215,... as numeric. I think Matlab understanding dates as numbers
Jos (10584)
Jos (10584) 2016년 6월 6일
A0 = [750525, 780215] A = arrayfun(@(x) sprintf('%06d',x), A0, 'un', 0) % convert to cell array of strings
davit petraasya
davit petraasya 2016년 6월 6일
This is great Jos, it works perfectly. Thank you a lot!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Steven Lord
Steven Lord 2016년 6월 6일

2 개 추천

Use the 'ConvertFrom' option with datetime to create a datetime object representing your date.
x = 19990511;
D = datetime(x, 'ConvertFrom', 'yyyymmdd')

카테고리

도움말 센터File Exchange에서 Time Series Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by