how to convert string to a daily datetime?

26 views (last 30 days)
I extracted the time array from (nc file), its a daily time arry for the year 1979, and below is sample of the extracted data.
The description of the nc file gave the following below details.
Can any one help me to convert the string numbers to the a datetime arry ?
Sample of the data
Time=[ 692496 692520 692544 692568 692592 692616 692640 692664 692688 692712 692736 692760 692784 692808 692832 692856 692880 692904 692928 692952 692976 693000 693024 693048 693072 693096 693120 693144 693168 693192 693216 693240 693264 693288 693312 693336 693360 693384 693408 693432 693456 693480 693504 693528 693552 693576 693600 693624 693648 693672 693696 693720 693744 693768 693792 693816 693840 693864 693888 693912 ]
Description of nc file about the time array
time
Size: 365x1
Dimensions: time
Datatype: double
Attributes:
long_name = 'Time'
axis = 'T'
standard_name = 'time'
coordinate_defines = 'start'
actual_range = [692496 701232]
delta_t = '0000-00-01 00:00:00'
avg_period = '0000-00-01 00:00:00'
units = 'hours since 1900-01-01 00:00:00'

Accepted Answer

Walter Roberson
Walter Roberson on 12 Nov 2024 at 19:56
DateTime = datetime('1900-01-01 00:00:00') + Time/24;
  2 Comments
Steven Lord
Steven Lord on 12 Nov 2024 at 20:19
Or taking advantage of the units description to make the code look closer to that description:
Time=[ 692496 692520 692544 692568 692592 692616 692640 692664 692688 692712 692736 692760 692784 692808 692832 692856 692880 692904 692928 692952 692976 693000 693024 693048 693072 693096 693120 693144 693168 693192 693216 693240 693264 693288 693312 693336 693360 693384 693408 693432 693456 693480 693504 693528 693552 693576 693600 693624 693648 693672 693696 693720 693744 693768 693792 693816 693840 693864 693888 693912 ];
dt1 = hours(Time) + datetime(1900, 01, 01); % 'hours since 1900-01-01 00:00:00'
dt2 = datetime('1900-01-01 00:00:00') + Time/24;
isequal(dt1, dt2)
ans = logical
1

Sign in to comment.

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!