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

2 次查看(过去 30 天)
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