How do I convert dates to days?
조회 수: 1 (최근 30일)
이전 댓글 표시
Let us say I have a series of dates: '01-01-2022', '05-01-2022', '06-01-2022' and I have corresponding data on these dates how do i convert the dates to an array that looks like this: [0,4,5]
Generally something like this:
댓글 수: 0
채택된 답변
Simon Chan
2022년 3월 18일
Use function days
DateStrings = {'01-01-2022','05-01-2022','06-01-2022'};
t = datetime(DateStrings,'InputFormat','dd-MM-yyyy');
days(t-t(1))
댓글 수: 0
추가 답변 (2개)
Stephen23
2022년 3월 18일
편집: Stephen23
2022년 3월 18일
Your example and explanation are inconsistent: your explanation shows difference between adjacent dates, your example vector shows differences to the first date. Here are both:
C = {'01-01-2022', '05-01-2022', '06-01-2022'};
T = datetime(C,'inputFormat','d-M-u');
V = days(T-T(1)) % what your example shows
D = [0,caldays(caldiff(T))] % what you explained
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!