フィルターのクリア

How do I convert a string to a datetime?

4 ビュー (過去 30 日間)
Shahar ben ezra
Shahar ben ezra 2020 年 11 月 18 日
コメント済み: Steven Lord 2020 年 11 月 21 日
Currently I have the string:
"19:00:06 01.04.20"
I want to convert this to a date, and I use the following function:
t=datetime(my_string,'InputFormat','HH:mm:ss dd.MM.yy')
but i get Error
I would be like to help :)
  1 件のコメント
Steven Lord
Steven Lord 2020 年 11 月 21 日
What is the full and exact text (everything written in red in the Command Window) you receive when you try to define that string and call datetime on it? The text of the message may give crucial clues as to why MATLAB cannot successfully run that call to datetime or at least suggest the next step to take to investigate the problem.

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

採用された回答

Cris LaPierre
Cris LaPierre 2020 年 11 月 18 日
Assign your string to the variable my_string
my_string = "19:00:06 01.04.20";
t=datetime(my_string,'InputFormat','HH:mm:ss dd.MM.yy')
t = datetime
01-Apr-2020 19:00:06
  2 件のコメント
Shahar ben ezra
Shahar ben ezra 2020 年 11 月 21 日
Thank you!
Maybe I made a mistake because it still does not work for me
I read the vector through the excel
I mean I get a string column
Could the answer now be different?
Cris LaPierre
Cris LaPierre 2020 年 11 月 21 日
You can use readtable to directly import this column as a datetime. See this page.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCalendar についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by