Cody

Problem 43275. calculate the day of the year from a date string.

Solution 2131461

Submitted on 17 Feb 2020 by Asif Newaz
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
start = '09-Oct-2016'; for i = 1:10 date = datestr(datenum(start) + i); doy_correct = 283 + i; doy = dayoftheyear(date); assert(isequal(doy, doy_correct)); end start = '04-Oct-1937'; for i = 1:10 date = datestr(datenum(start) + i); doy_correct = 277 + i; doy = dayoftheyear(date); assert(isequal(doy, doy_correct)); end

b = datetime 10-Oct-2016 doy = 284 b = datetime 11-Oct-2016 doy = 285 b = datetime 12-Oct-2016 doy = 286 b = datetime 13-Oct-2016 doy = 287 b = datetime 14-Oct-2016 doy = 288 b = datetime 15-Oct-2016 doy = 289 b = datetime 16-Oct-2016 doy = 290 b = datetime 17-Oct-2016 doy = 291 b = datetime 18-Oct-2016 doy = 292 b = datetime 19-Oct-2016 doy = 293 b = datetime 05-Oct-1937 doy = 278 b = datetime 06-Oct-1937 doy = 279 b = datetime 07-Oct-1937 doy = 280 b = datetime 08-Oct-1937 doy = 281 b = datetime 09-Oct-1937 doy = 282 b = datetime 10-Oct-1937 doy = 283 b = datetime 11-Oct-1937 doy = 284 b = datetime 12-Oct-1937 doy = 285 b = datetime 13-Oct-1937 doy = 286 b = datetime 14-Oct-1937 doy = 287

Suggested Problems

More from this Author15

Community Treasure Hunt

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

Start Hunting!