Date conversion using GMT

3 views (last 30 days)
John
John on 12 Dec 2011
I have a specific application in which I am reading in data into an array that includes a year (as an individual cell) and a GMT day. I need to convert the GMT day into an actual date using the year. If the year is in variable yr and GMT date in dGMT, I assumed that I could use the datestr function as follows:
d = datestr(addtodate(dGMT),floor(yr*365.25),'day'))
where datestr of the GMT returned the date in year 0000, and I simply add the amount of days that have elapsed since 1/1/0000. However, the data that is computed is off by about 2 weeks.
I did some investigating, and tried the above line of code with various years and dGMT=1.
I got the following: K>> datestr(addtodate((1),floor(1582*365.25),'day'))
ans =
31-Dec-1581
K>> datestr(addtodate((1),floor(1583*365.25),'day'))
ans =
10-Jan-1583
It seems that between year 1582 and 1583 10 days get added. Can anyone explain why, or possibly suggest another way to get the date?

Answers (1)

Walter Roberson
Walter Roberson on 12 Dec 2011
There is actually good reason; see http://en.wikipedia.org/wiki/Gregorian_calendar

Community Treasure Hunt

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

Start Hunting!