Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Suppose the user inserts an integer n and a date string '1/1/2015' (stands for Jan 1 2015), then how do I find the date that is n days before Jan 1 2015?

1 Ansicht (letzte 30 Tage)
It seems minus sign doesn't work. Any date function can help?
  1 Kommentar
jgg
jgg am 17 Dez. 2015
A string does not work with the minus sign, as you'd expect. You need to convert the string to a number, subtract your n, then convert it back to a date string to output. Take a look at Matlab's date functions to see how to do this.

Antworten (1)

Walter Roberson
Walter Roberson am 18 Dez. 2015
d = datetime('1/1/2015', 'InputFormat', 'M/d/Y');
d - days(n)
  2 Kommentare
Shawn Miller
Shawn Miller am 24 Dez. 2015
Thanks, it seems it should be y rather than Y. Also, the result returned from d - days(n) also includes time. Anyway, it partially works.

Diese Frage ist geschlossen.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by