Cody

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

Solution 2869766

Submitted on 23 Aug 2020 by VENKATESH VISHNURAM
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

k = datetime 10-Oct-2016 doy = 284 k = datetime 11-Oct-2016 doy = 285 k = datetime 12-Oct-2016 doy = 286 k = datetime 13-Oct-2016 doy = 287 k = datetime 14-Oct-2016 doy = 288 k = datetime 15-Oct-2016 doy = 289 k = datetime 16-Oct-2016 doy = 290 k = datetime 17-Oct-2016 doy = 291 k = datetime 18-Oct-2016 doy = 292 k = datetime 19-Oct-2016 doy = 293 k = datetime 05-Oct-1937 doy = 278 k = datetime 06-Oct-1937 doy = 279 k = datetime 07-Oct-1937 doy = 280 k = datetime 08-Oct-1937 doy = 281 k = datetime 09-Oct-1937 doy = 282 k = datetime 10-Oct-1937 doy = 283 k = datetime 11-Oct-1937 doy = 284 k = datetime 12-Oct-1937 doy = 285 k = datetime 13-Oct-1937 doy = 286 k = 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!