Transforming an integer vector into dates text vector

조회 수: 23 (최근 30일)
Mohamed Larabi
Mohamed Larabi 2018년 5월 28일
댓글: Star Strider 2018년 5월 28일
I am having a vector corresponding to dates in the following format yyyymmdd, ie for December 24th, 2010 it is 20101224. How can I transform this vector of integers into text dates in the following format 'mm-dd-yyyy'?

채택된 답변

Star Strider
Star Strider 2018년 5월 28일
Assuming your original vector is numeric, there are two options:
dates = [20101224; 20101225; 20101226];
ds1 = datestr(datenum(num2str(dates), 'yyyymmdd'), 'mm-dd-yyyy'); % Use ‘datenum’ & ‘datestr’
ds2 = datetime(num2str(dates), 'InputFormat','yyyyMMdd', 'Format','MM-dd-yyyy'); % Use ‘datetime’
  댓글 수: 2
Mohamed Larabi
Mohamed Larabi 2018년 5월 28일
Thank you very much. It is perfect!
Star Strider
Star Strider 2018년 5월 28일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by