Calculate the number of days in a year

조회 수: 3 (최근 30일)
FCC
FCC 2013년 4월 21일
Is it possible to calculate the number of days in a year without having to put the year? If so how? Also i'm doing this on an m-file.

답변 (2개)

Royi Avital
Royi Avital 2013년 4월 21일
I would go something like that:
firstDayInYear = '01/01/2012';
lastDayInYear = '31/12/2012';
firstDayInYearNum = datenum(firstDayInYear, 'dd/mm/yyyy');
lastDayInYearNum = datenum(lastDayInYear, 'dd/mm/yyyy');
numDaysInYear = lastDayInYearNum - firstDayInYearNum + 1;
That's it...

per isakson
per isakson 2013년 4월 21일
Or one of
y = 2002;
datenum([y+1,1,1]) - datenum([y,1,1])
sum( eomday( y, [1:12] ) )

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by