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 件)
KSSV
2021 年 12 月 12 日
You can convert dates which are in datetime class using the function datenum.
0 件のコメント
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!