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 日

0 投票

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 日

1 投票

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')

1 件のコメント

Andrei Bobrov
Andrei Bobrov 2017 年 6 月 3 日
Thank you Peter!

サインインしてコメントする。

カテゴリ

ヘルプ センター および File 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