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
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
2015-12-18
d = datetime('1/1/2015', 'InputFormat', 'M/d/Y');
d - days(n)
2 个评论
Walter Roberson
2015-12-24
d = datetime('1/1/2015', 'InputFormat', 'M/d/y', 'Format', 'M/d/y');
d - days(n)
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!