How to change datenum to normal date format?
5 views (last 30 days)
Show older comments
Hi all,
I have tried using following command but as a result date has wrong year and they are not in sequence too:
datestr(A{1})
>>'01-Jul-4447'
'25-Jul-4447'
'18-Aug-4447'
'11-Sep-4447'
'05-Oct-4447'
'29-Oct-4447'
datetime(A{1}, 'ConvertFrom', 'datenum', 'Format', 'dd-MM-yyyy')
>>01-07-4447
25-07-4447
18-08-4447
11-09-4447
05-10-4447
29-10-4447
datevec(A{1})
>>4447 7 1 0 0 0
4447 7 25 0 0 0
4447 8 18 0 0 0
4447 9 11 0 0 0
4447 10 5 0 0 0
4447 10 29 0 0 0
I have attached a dummy data here in this link:
0 Comments
Answers (2)
Walter Roberson
on 26 Feb 2021
filename = 'olr_1985.nc';
times = hours(ncread(filename, 'time')) + datetime(1800,1,1, 'format', 'yyyy-MM-dd hh:mm');
Results are 1985-01-01 12:00 to 1985-04-30 12:00
ANKUR KUMAR
on 26 Feb 2021
You can use this function from the matlab file exchange to read time from a ncetcf file in user specified format: https://in.mathworks.com/matlabcentral/fileexchange/87894-ncreadtime
An example is shown below using the file you attached:
file='olr_1985.nc'
ncreadtime(ncread(file,'time'),ncreadatt(file,'time','units'),'yyyymmdd_HH')
See Also
Categories
Find more on Calendar in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!