MATLAB: Convert vector of weeks to dates

datedouble to timetime

I know this must be simple but I am struggling. I have a vector of values t = [0, 0.12, 0.3, 2], and I would like to get a date vector where the first element is a given date (1/3/2020 say) and the other three elements are dates where t gives the number of weeks from the initial date. E.g. the fourth element is 2 weeks after 1/3/2020 i.e. 15/3/2020). Somehow I cannot find a way of doing this. Thanks!

Best Answer

  • d=datetime('01/03/2020','InputFormat','dd/MM/yyyy','Format','dd/MM/yyyy');
    t = [0, 0.12, 0.3, 2];
    w=days(round(7*t));
    nd=d+w;