필터 지우기
필터 지우기

How to calculate difference between dates while values in rows are equal?

조회 수: 2 (최근 30일)
Louisa pauen
Louisa pauen 2018년 2월 5일
답변: vijaya lakshmi 2018년 2월 26일
Hi all, I want to find rows where the values in the first column of the matrix are equal (identifying number for stocks) and calculate the difference between the the start date of equal values and the last date of equal values. Then I want to check if the difference between dates are < 20 and if so, I want to delete the part of the matrix between the dates. In the file attached, the first column if the identifying number of the stocks, and the second column are the dates in serial date numbers. Hope anyone can help!
Many thanks in advance!

답변 (1개)

vijaya lakshmi
vijaya lakshmi 2018년 2월 26일
Hi Louisa,
In order to find the difference between 2 dates which are stored in 'serial date number' format
First, convert the "serial date number" format to "date" format
t1=datetime(725617,'ConvertFrom','datenum');
t2=datetime(725618,'ConvertFrom','datenum');
Later find the difference between dates
diff= datenum(t2) - datenum(t1);
Or the other way is, directly find the difference between the dates which are in "serial date number" format
datenum(725620)-datenum(725619)

카테고리

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