converting a date into a num
3 次查看(过去 30 天)
显示 更早的评论
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 ?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/831945/image.png)
0 个评论
回答(2 个)
Star Strider
2021-12-12
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
dnv = datetime([[63067800; 63068400; 63069000; 63069600; 63070200; 63070800; 63071400; 63072000] ones(8,1)] * B, 'ConvertFrom','datenum')
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.)
.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!