필터 지우기
필터 지우기

I am not getting the correct answer when using datetime function

조회 수: 1 (최근 30일)
gsourop
gsourop 2019년 9월 17일
댓글: Guillaume 2019년 9월 17일
Hi everyone,
I am using the following function
datetime(1,43100,1)
but instead of getting '31/12/2017' as an answer (as given from Excel), I am getting 01-Aug-3592. Apparently, I am missing something in the datetime function but don't know what it is.
Thanks in advance for your time.

채택된 답변

dpb
dpb 2019년 9월 17일
>> datetime(43100,'ConvertFrom','excel')
ans =
datetime
31-Dec-2017 00:00:00
>>
You tried converting from (yr,mo,day) --> (1, 43100, 1) instead.
  댓글 수: 2
gsourop
gsourop 2019년 9월 17일
Thank you very much for the answer! How can I ignore the time part. I want to end up just with '31-Dec-2017' instead of '31-Dec-2017 00:00:00' .
Guillaume
Guillaume 2019년 9월 17일
The time part is always part of a datetime (hence the time in the name). You can avoid displaying it by changing the Format property:
>> datetime(43100,'ConvertFrom','excel', 'Format', 'dd-MM-yyyy')
ans =
datetime
31-12-2017
>> datetime(43100,'ConvertFrom','excel', 'Format', 'eee dd MMM yyyy')
ans =
datetime
Sun 31 Dec 2017
but note that the time part will still be taken into account for calculations (like date difference) whether or not it is displayed. Excel does the same.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Ted Shultz
Ted Shultz 2019년 9월 17일
편집: Ted Shultz 2019년 9월 17일
You are using
t = datetime(Y,M,D)
Year = 1
month = 43100
day = 1
That is not what you intend I assume.
I think you want:
t = datetime(43100,'ConvertFrom','excel')

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by