Convert gregorian day to yyyy-mm

13 views (last 30 days)
주희 박
주희 박 on 12 Jul 2022
Commented: 주희 박 on 13 Jul 2022
Hi, I attached 'Time' variable from 1995-01-01~2021-12-15 and it is monthly data.
It's units = 'days since 1950-01-01 00:00:00
I want to convert it yyyy-mm .
This is what i tried
  1. TT=datetime(1995,1,1)+hours(time); -> It starts 1996-11~
  2. TT=years(time) ->Absolutely wrong
  3. TT=datetime(time,'ConvertFrom','epochtime','Epoch','1950-01-01');->It's unit is seconds. Wrong
Please help me. Thanks.

Accepted Answer

Chunru
Chunru on 12 Jul 2022
load Time.mat
%time
dt = datetime("1950-01-01 00:00:00") + days(time)
dt = 324×1 datetime array
15-Jan-1995 15-Feb-1995 15-Mar-1995 15-Apr-1995 15-May-1995 15-Jun-1995 15-Jul-1995 15-Aug-1995 15-Sep-1995 15-Oct-1995 15-Nov-1995 15-Dec-1995 15-Jan-1996 15-Feb-1996 15-Mar-1996 15-Apr-1996 15-May-1996 15-Jun-1996 15-Jul-1996 15-Aug-1996 15-Sep-1996 15-Oct-1996 15-Nov-1996 15-Dec-1996 15-Jan-1997 15-Feb-1997 15-Mar-1997 15-Apr-1997 15-May-1997 15-Jun-1997

More Answers (0)

Community Treasure Hunt

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

Start Hunting!