How to correctly use MONTHS function?

2 ビュー (過去 30 日間)
Namrata Goswami
Namrata Goswami 2021 年 2 月 16 日
回答済み: Sean de Wolski 2021 年 4 月 11 日
I am trying to find the difference between dates in "months". I have refferred to the following documentation on usage of "months" function and I even tried out the example given in the documentation but all I get is an error.
Code: MyMonths = months('may 31 2000', 'jun 30 2000', 1)
Error: Check for missing argument or incorrect argument data type in call to function 'months'.
What am I missing?

回答 (2 件)

randerss simil
randerss simil 2021 年 2 月 16 日
編集済み: randerss simil 2021 年 2 月 16 日
Type
which months
at the command window
If you see more than two functions with filenames months then it may be due to custom function and not standard matlab function

Sean de Wolski
Sean de Wolski 2021 年 4 月 11 日
You should use datetimes, durations and the between function for this:
>> d1 = datetime('may 31 2000', 'InputFormat', 'MMM dd yyyy')
d1 =
datetime
31-May-2000
>> d2 = datetime('jun 30 2000', 'InputFormat', 'MMM dd yyyy')
d2 =
datetime
30-Jun-2000
>> monthsbetween = between(d1, d2, 'months')
monthsbetween =
calendarDuration
1mo

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by