convert date and time in seconds

조회 수: 31 (최근 30일)
Nivodi
Nivodi 2018년 9월 4일
댓글: jonas 2018년 9월 5일
Hello everyone, I have a table with several variables. Among others, I have 2 columns with date and time. These 2 columns are cells with strings ('iscellstr'=1 and 'ischar'=0). How can I convert them in seconds? thank you very much!
  댓글 수: 7
jonas
jonas 2018년 9월 4일
Not sure what you are doing, but that is not the correct syntax. I wrote some lines of code in the answer section to give you an idea of what I meant.
Nivodi
Nivodi 2018년 9월 4일
I wrote that before I saw the answer that you wrote below. I am working on it now.

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

채택된 답변

jonas
jonas 2018년 9월 4일
편집: jonas 2018년 9월 4일
Here's a solution with datetime
data=load('matlab.mat')
T=data.T1_B6_09032017;
TimeOfDay=duration(T.time)
Date=datetime(T.date,'inputformat','dd.MM.yyyy')
t=Date+TimeOfDay;
If you really want the output in seconds, here is how you calculate the duration from the first measurement:
ts=seconds(t-t(1));
I suggest you then put the data in a timetable
TT=timetable(t,T);
TT=splitvars(TT);
  댓글 수: 8
Nivodi
Nivodi 2018년 9월 5일
Thank you Jonas for your time and help!
jonas
jonas 2018년 9월 5일
My pleasure! Don't forget to accept if the answer was helpful!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by