How do I convert a string to a datetime?

조회 수: 8 (최근 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 CenterFile Exchange에서 Calendar에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by