# Conversion of Gregorian date to decimal years

16 views (last 30 days)
Ahmet Hakan UYANIK on 9 May 2021
Commented: Walter Roberson on 10 May 2021
Hi,
I have time series given in gregorian time in seconds since 1992-01-01 00:00:00'. For example; 23853938,23853939...
How can i convert this gregorian time seconds to decimal years like 2010.544, 2010.545...

Walter Roberson on 10 May 2021
basetime = datetime('1992-01-01 00:00');
gtime = 23853938
t1 = basetime + seconds(gtime)
t2 = dateshift(t1, 'start', 'year')
t3 = dateshift(t1, 'end', 'year')
fy = year(t1) + (t1-t2)./(t3-t2)
##### 3 CommentsShow 1 older commentHide 1 older comment
Ahmet Hakan UYANIK on 10 May 2021
Edited: Walter Roberson on 10 May 2021
it is giving similar results as I did actually, what I do is;
T = datetime(1992,1,1) + seconds(gtime);
T.Format = 'yyyy-MM-dd HH:mm:ss';
dy = decyear(T)
both are correct, I guess :) Thank you in advance
Walter Roberson on 10 May 2021
decyear() appears to require the Areospace Toolbox.
Also, setting the Format is not required for decyear()