Rajan
Rajan

Reputation: 145

stuck with Julian Calendar Day formats in PHP

I get data from an API which has 253 as the Julian date value. This translates to 10 Sep for some years... in this API, though the year is not mentioned, it is for 2019 (not a leap year). I see the conversion at https://landweb.modaps.eosdis.nasa.gov/browse/calendar.html , for example. The year is implicit (it is always the current year).

However, in PHP, how do I "add" the year to it so that I can get the timestamp or any other date format that i need? None of the calendar functions in PHP like cal_from_jd or jdtogregorian work. They give me year as "-4713", which is why i need to "add" the year

Any help will be helpful

Thanks

Upvotes: 0

Views: 187

Answers (1)

jspit
jspit

Reputation: 7703

The Julian date is the number of days since January 1 -4712. The number you get from the API is probably the number of days in the current year. It is not difficult to calculate a date from it:

$daysFromApi = 253;

$dateTime = date_create("01/01 +$daysFromApi Days");

//Output
echo $dateTime->format("Y-m-d");  //2020-09-10

Upvotes: 1

Related Questions