converting a date into a num

5 visualizaciones (últimos 30 días)
Aleksandra Ksiezyk
Aleksandra Ksiezyk el 12 de Dic. de 2021
Respondida: Star Strider el 12 de Dic. de 2021
I have a structure with 2 columns. When i click on a struction icon i see my dates (Time): dd-mmm-yyy HH:MM:SS (like in a pic above: 01-Jan-2016 00:00:00 ). When i click my dates (Time) of the same structure from the Workspace i get results already converted into a num (doubble). The problem is when i type str(myStructure.Time) i am getting: '08-Apr-2685' (This is the last value). has anyone an idea why is that ?

Respuestas (2)

KSSV
KSSV el 12 de Dic. de 2021
You can convert dates which are in datetime class using the function datenum.

Star Strider
Star Strider el 12 de Dic. de 2021
I have no idea what those date numbers are, since they are not MATLAB date numbers, and attempting to convert them as 'excel' or 'posix' fails completely.
Try using a bit of linear algebra to convert them to MATLAB datenum numbers, then convert them to datetime arrays —
dn = datenum([2015 12 31 22 30 00; 2015 12 31 22 40 00]); % Necessary
B = [[63067800; 63068400] ones(2,1)] \ dn; % Necessary (Mapping Vector)
PivotYear = datetime(B(2), 'ConvertFrom','datenum') % Simply Out Of Curiosity
PivotYear = datetime
31-Dec-2013 23:39:59
dnv = datetime([[63067800; 63068400; 63069000; 63069600; 63070200; 63070800; 63071400; 63072000] ones(8,1)] * B, 'ConvertFrom','datenum')
dnv = 8×1 datetime array
31-Dec-2015 22:30:00 31-Dec-2015 22:40:00 31-Dec-2015 22:50:00 31-Dec-2015 23:00:00 31-Dec-2015 23:10:00 31-Dec-2015 23:20:00 31-Dec-2015 23:30:00 31-Dec-2015 23:40:00
Copying them from the Command Window — or better yet, saving them to a variable as a column vector — and then using this approach will likely convert all of them successfully. (It would be nice to know what they are and how to convert them if the encoding is known.)
.

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by