Parse variable in a table

조회 수: 1 (최근 30일)
Inna Pelloso
Inna Pelloso 2023년 8월 8일
댓글: Star Strider 2023년 8월 8일
Hi,
I have a variable in a table, timestamp, in the following format:
2023-02-24 13:00:00
How can I parse this variable into two new variables, date (2023-02-24) and time (13:00:00)?
Any help would be appreciated!
IP

채택된 답변

Star Strider
Star Strider 2023년 8월 8일
편집: Star Strider 2023년 8월 8일
Several options, depending on what you want —
timestamp = '2023-02-24 13:00:00'
timestamp = '2023-02-24 13:00:00'
DT = datetime(timestamp)
DT = datetime
24-Feb-2023 13:00:00
Date = DT;
Time = DT;
Date.Format = 'yyyy-MM-dd'
Date = datetime
2023-02-24
Time.Format = 'HH:mm:ss'
Time = datetime
13:00:00
Date = extractBefore(timestamp, ' ')
Date = '2023-02-24'
Time = extractAfter(timestamp, ' ')
Time = '13:00:00'
DateTime = strsplit(timestamp, ' ')
DateTime = 1×2 cell array
{'2023-02-24'} {'13:00:00'}
EDIT — Added strsplit call.
.
  댓글 수: 2
Inna Pelloso
Inna Pelloso 2023년 8월 8일
Thank you!
Star Strider
Star Strider 2023년 8월 8일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by