How to covert a datenum (serial number) back to original date time format

조회 수: 7 (최근 30일)
Gali Musa
Gali Musa 2018년 6월 14일
답변: Peter Perkins 2018년 7월 5일
I have a column of datenum and i want to change it back to the original date and time. i use DateNumber = datetime(time, 'ConvertFrom','datenum'); but the time is not the same with the original one. Sample example; time 01/01/2013 00:00 01/01/2013 00:15 01/01/2013 00:30 01/01/2013 00:45 01/01/2013 01:00 01/01/2013 01:15 01/01/2013 01:30 01/01/2013 01:45 01/01/2013 02:00 this is what i have in a multiple columns and i converted the string date to a serial in order to make the calculation. after i finished all the calculation want to return back the date and time to its original. Here is the sample for that
time 735235 735235 735235 735235 735235 735235 735235 735235 735235 735235 i used datenum sytax and here is it DateNumber = datenum(X)
i want to change the serialnumber back to its original position
  댓글 수: 1
Jan
Jan 2018년 6월 14일
Without knowing what "the original one" is, neither the readers in this forum nor Matlab can apply the wanted conversion. A datenum is a floating point values. It does not carry any magic information about how this number has been represented before.
Please edit the question and add the information, what you want to get exactly.

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

답변 (1개)

Peter Perkins
Peter Perkins 2018년 7월 5일
There's not enough in your description to go on, but a round-trip certainly does work in your example:
>> dn = 735235 + (0:15:120)/1440
dn =
Columns 1 through 4
735235 735235.010416667 735235.020833333 735235.03125
Columns 5 through 8
735235.041666667 735235.052083333 735235.0625 735235.072916667
Column 9
735235.083333333
>> d = datetime(dn,'ConvertFrom','datenum')
d =
1×9 datetime array
Columns 1 through 5
01-Jan-2013 00:00:00 01-Jan-2013 00:15:00 01-Jan-2013 00:30:00 01-Jan-2013 00:45:00 01-Jan-2013 01:00:00
Columns 6 through 9
01-Jan-2013 01:15:00 01-Jan-2013 01:30:00 01-Jan-2013 01:45:00 01-Jan-2013 02:00:00
>> dn2 = datenum(d)
dn2 =
Columns 1 through 4
735235 735235.010416667 735235.020833333 735235.03125
Columns 5 through 8
735235.041666667 735235.052083333 735235.0625 735235.072916667
Column 9
735235.083333333
>> dn - dn2
ans =
0 0 0 0 0 0 0 0 0

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by