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

3 Ansichten (letzte 30 Tage)
Gali Musa
Gali Musa am 14 Jun. 2018
Beantwortet: Peter Perkins am 5 Jul. 2018
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 Kommentar
Jan
Jan am 14 Jun. 2018
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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Peter Perkins
Peter Perkins am 5 Jul. 2018
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

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by