Why do I see different results when passing dates from Excel into MATLAB?

Why do I get different results when passing dates from Excel into MATLAB?
For example, if the date: 10/10/1998 is entered in Excel and then put into MATLAB, the results differ by 693960. Here is a short example. Import the cell containing the date 10/10/1998 into MATLAB with the variable name foo.
+ datenum('10/10/1998') - foo
ans =
693960

 Accepted Answer

This issue is occuring because MATLAB and Excel use different starting numbers for their datenumbers.
The workaround is to always pass strings or to offset any datenumbers by 693960.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!