Convert scalar values into date time and viceversa

Hello, I want to obtain an estimated date in the future from adding a numerical value (converted into date) plus today's date. In other words, take today's date and sum it to the equivalent date in years, months and days from a scalar result previously obtained.
Any body have an idea. Is it possible?
Thanks in advance.
Anatoly Kurman Rivero

Answers (2)

One approach:
D = datetime('now');
Future = D + days(1000)
producing:
Future =
datetime
05-Feb-2022 09:13:39
Experiment to get the result you want.
EDIT —
Offset = days(Future - D)
Offset =
1000
Hi,
It is possible and here is the command syntax:
DateStr = '12-May-2019';
FormatIn = 'dd-mmm-yyyy';
Today = datenum(DateStr,FormatIn)
DateNumber = Today+1;
FormatOut = 'mmmm-dd-yyyy';
str = datestr(DateNumber,FormatOut,'local')
vice-versa:
Good luck.

Asked:

on 12 May 2019

Edited:

on 12 May 2019

Community Treasure Hunt

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

Start Hunting!