Effacer les filtres
Effacer les filtres

Adding month values to datetime function

35 vues (au cours des 30 derniers jours)
Jay
Jay le 26 Mai 2016
Commenté : Andrei Bobrov le 27 Mai 2016
If I have a datetime value of today, can I add 3 or 6 months to that value without splitting the date into 3 separate arrays (dd, MM, yyyy)?

Réponses (2)

Andrei Bobrov
Andrei Bobrov le 26 Mai 2016
Modifié(e) : Andrei Bobrov le 26 Mai 2016
out = datetime('now') + calmonths([3,6])
before R2014b
out = addtodate(now ,[3,6],'month')
  5 commentaires
Andrei Bobrov
Andrei Bobrov le 27 Mai 2016
Yes, if your date(ObsDate) - scalar serial date number (read doc about addtodate)
Andrei Bobrov
Andrei Bobrov le 27 Mai 2016
if ObsDate and Q - array example:
ObsDate = [2016 5 29;2016 6 14];
Q = [3 4 15];
D = datenum(ObsDate);
a = bsxfun(@(x,y)addtodate(x,y,'month'),D(:),Q(:)');
out = arrayfun(@datestr,a,'un',0)

Connectez-vous pour commenter.


Jay
Jay le 27 Mai 2016
Modifié(e) : Jay le 27 Mai 2016
Never mind I figured out what was wrong.
CalWin = datenum(ObsDate)
CalWin = addtodate(CalWin, 3, 'month')
datestr(CalWin)

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by