필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

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 (최근 30일)
It seems minus sign doesn't work. Any date function can help?
  댓글 수: 1
jgg
jgg 2015년 12월 17일
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.

답변 (1개)

Walter Roberson
Walter Roberson 2015년 12월 18일
d = datetime('1/1/2015', 'InputFormat', 'M/d/Y');
d - days(n)
  댓글 수: 2
Shawn Miller
Shawn Miller 2015년 12월 24일
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.

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by