Info

This question is closed. Reopen it to edit or answer.

datenum problem with conversion

2 views (last 30 days)
jenka
jenka on 18 Jan 2017
Closed: MATLAB Answer Bot on 20 Aug 2021
I have a question. I am trying to use datenum function as below. Question: why ans1=ans2? Am I using format wrongly? Thank you!
ans1 = datenum('4:30:00 PM','HH:MM:SS PM')
ans1 =
7.3670e+05
ans2 = datenum('2:30:00 PM','HH:MM:SS PM')
ans2 =
7.3670e+05
  2 Comments
Stephen23
Stephen23 on 19 Jan 2017
Are they the same?
>> format longg
>> datenum('4:30:00 PM','HH:MM:SS PM')
ans =
736696.6875
>> datenum('2:30:00 PM','HH:MM:SS PM')
ans =
736696.604166667

Answers (1)

Star Strider
Star Strider on 18 Jan 2017
They’r not the same. Use the format function to display the entire number in full precision:
format long g
ans1 = datenum('4:30:00 PM','HH:MM:SS PM')
ans2 = datenum('2:30:00 PM','HH:MM:SS PM')
ans1 =
736696.6875
ans2 =
736696.604166667
  1 Comment
Jan
Jan on 19 Jan 2017
Alternatively:
ans1 = datenum('4:30:00 PM','HH:MM:SS PM')
ans2 = datenum('2:30:00 PM','HH:MM:SS PM')
ans1 - ans2
% And:
(ans1 - ans2) * 86400

Tags

Community Treasure Hunt

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

Start Hunting!