필터 지우기
필터 지우기

how to combine date and time in single column

조회 수: 9 (최근 30일)
MONICA RAWAT
MONICA RAWAT 2020년 5월 22일
댓글: Steven Lord 2023년 4월 19일
suppose i have one table of date and another table of time as given below
date time
2013-11-23 23:32:29
2013-12-24 22:29:38
then i want my output to be given below in a single table
datetime
2013-11-23 23:32:29
2013-12-24 22:29:38
  댓글 수: 2
KSSV
KSSV 2020년 5월 22일
편집: KSSV 2020년 5월 22일
strjoin, strcat.
[date time]
MONICA RAWAT
MONICA RAWAT 2020년 5월 22일
both of these function is not working

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

답변 (1개)

Steven Lord
Steven Lord 2020년 5월 22일
In what data type is your data stored?
If it's stored as char vectors then you can use the functions KSSV mentioned in the comment.
C = table();
C.date = ['2013-11-23'; '2013-12-24'];
C.time = ['23:32:29'; '22:29:38'];
C.dateAndTime = strcat(C.date, {' '}, C.time)
If they are a datetime and a duration just add them together.
C = table();
C.date = datetime({'2013-11-23'; '2013-12-24'});
C.time = duration({'23:32:29'; '22:29:38'});
C.dateAndTime = C.date + C.time
  댓글 수: 4
Walter Roberson
Walter Roberson 2023년 4월 19일
Suppose you have an array TimeOfDay that is intended to be hour/minutes/seconds but got stored in the form of datetime, and suppose you have a Date array that got stored in the form of datetime. Then
DateTime = Date + (TimeOfDay - dateshift(TimeOfDay, 'start', 'day'));
As usual you should be asking questions about what happens when Daylight Savings Time begins or ends.
Steven Lord
Steven Lord 2023년 4월 19일
I have both dates and times as datetime and when I try adding them I get error that says addition is not possible between datetime arrays.
That's correct. What would you expect the result to be if you could add today and tomorrow together? No, some date and time in the year 4046 would not be the correct answer IMO.
The dateshift approach Walter suggested is one possible solution, another would be to use the hms function on one of the datetime arrays.
dt = datetime('now')
dt = datetime
19-Apr-2023 23:25:18
[h1, m1, s1] = hms(dt)
h1 = 23
m1 = 25
s1 = 18.0110
du = duration(h1, m1, s1)
du = duration
23:25:18

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

카테고리

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