Coverting specific string containing date to datetime

12 ビュー (過去 30 日間)
Joanna Przeworska
Joanna Przeworska 2021 年 3 月 9 日
回答済み: Joanna Przeworska 2021 年 3 月 9 日
Dear all,
Let say I have a dataset with the variable 'Period', which want to convert to a datetime: 2012-12-01; 2013-03-01, 2013-06-01, ...
I know I must somehow extract year and quarter from the variable and create new datetime variable based on that, could you help me with the exact code?
Period
'2012_Q4'
'2013_Q1'
'2013_Q2'
'2013_Q3'
'2013_Q4'
'2014_Q1'
'2014_Q2'
'2014_Q3'
'2014_Q4'

採用された回答

Stephen23
Stephen23 2021 年 3 月 9 日
編集済み: Stephen23 2021 年 3 月 9 日
C = {...
'2012_Q4'
'2013_Q1'
'2013_Q2'
'2013_Q3'
'2013_Q4'
'2014_Q1'
'2014_Q2'
'2014_Q3'
'2014_Q4'};
T = datetime(C, 'InputFormat','yyyy_QQQ', 'Format','yyyy-MM-dd');
T = T + calmonths(2)
T = 9×1 datetime array
2012-12-01 2013-03-01 2013-06-01 2013-09-01 2013-12-01 2014-03-01 2014-06-01 2014-09-01 2014-12-01

その他の回答 (1 件)

Joanna Przeworska
Joanna Przeworska 2021 年 3 月 9 日
Dear Cris and Stephen,
Thank you for your suggestions.
Kind regards,
JP

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by