How to convert a string into a date or datenum?

5 ビュー (過去 30 日間)
Bruno Carvalho
Bruno Carvalho 2021 年 6 月 17 日
コメント済み: Stephen23 2021 年 6 月 18 日
I have a column, about [4000 x 1] with the format 'yyyymmddHH'. Yes, all the numbers are together.
And i need to get a date, or a datenum from that, but i cant, since functions like datetime need the numbers separated.
Anyone know how to get arround this?
Thank you.

回答 (1 件)

Stephen23
Stephen23 2021 年 6 月 17 日
編集済み: Stephen23 2021 年 6 月 17 日
"... but i cant, since functions like datetime need the numbers separated."
I don't see that restriction mentioned anywhere in the DATETIME documentation.
S = ["2021061701";"2021010100";"1913061423"]
S = 3×1 string array
"2021061701" "2021010100" "1913061423"
D = datetime(S, 'InputFormat','yyyyMMddHH')
D = 3×1 datetime array
17-Jun-2021 01:00:00 01-Jan-2021 00:00:00 14-Jun-1913 23:00:00
  6 件のコメント
Bruno Carvalho
Bruno Carvalho 2021 年 6 月 18 日
If you can, answer again in a seperate answer so i can accept your answer
Stephen23
Stephen23 2021 年 6 月 18 日
@Bruno Carvalho: you can accept this answer, if one of the comments includes the solution.

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

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by