date computations in a table

조회 수: 1 (최근 30일)
Danielle Leblance
Danielle Leblance 2017년 6월 1일
댓글: Andrei Bobrov 2017년 6월 3일
I have a table LC that has a column of dates called "date". The date format is however 19850331. I want to extract the year and the month of this date. How can I do so?

채택된 답변

Andrei Bobrov
Andrei Bobrov 2017년 6월 1일
편집: Andrei Bobrov 2017년 6월 1일
LC.date = datetime(sprintfc('%d',LC.date),'InputFormat','yyyyMMdd');
LC.month_year = [month(LC.date),year(LC.date)]

추가 답변 (1개)

Peter Perkins
Peter Perkins 2017년 6월 2일
Andrei provided the right answer if those data are text, e.g. '19850331' or "19850331". If they are numeric, use
datetime(LC.Date,'ConvertFrom','yyyymmdd')

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by