Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 681
  • Last Modified:

Given Julian Date - What Month & Day?

Is anyone out there aware of an algorithm (or some useable code) to get the month and day from a given Julian date and year?
0
awd
Asked:
awd
1 Solution
 
ozoCommented:
int l,n,i,j,d,m,y;
 l = jdn + 68569;
 n = ( 4 * l ) / 146097;
 l = l - ( 146097 * n + 3 ) / 4;
 i = ( 4000 * ( l + 1 ) ) / 1461001;
 l = l - ( 1461 * i ) / 4 + 31;
 j = ( 80 * l ) / 2447;
 d = l - ( 2447 * j ) / 80;
 l = j / 11;
 m = j + 2 - ( 12 * l );
 y = 100 * ( n - 49 ) + i + l;
printf("%d-%02d-%02d\n",y,m,d);
0
 
AlanB082898Commented:
I found this on http://quasar.as.utexas.edu/BillInfo/JulianDatesG.html
To convert a Julian Day Number to a Gregorian date, assume that it is for 0 hours, Greenwich time (so that it ends in 0.5). Do the following calculations, again dropping the fractional part of all multiplicatons and divisions. Note: This method will not give dates accurately on the Gregorian Proleptic Calendar, i.e., the calendar you get by extending the Gregorian calendar backwards to years earlier than 1582. using the Gregorian leap year rules. In particular, the method fails if Y<400.

  Z = JD+0.5
  //add .5 due to change in start of day from 12noon to
  //12 midnight
  W = (Z - 1867216.25)/36524.25
  //number of days for leap years?
  //don't know where 1867216.25 comes from.
  //365.2425 is the average number of days in the year
  //according to the Gregorian calandar
  X = W/4
  //number of days for leap years including some that don't
  //count. Like the years not evenly divisible by 400
  A = Z+1+W-X
  //total number of julian days plus leap year days?
  B = A+1524
  //don't know why they add 1524
  //days for the number of years + 1
  C = (B-122.1)/365.25
  //total years from Julian day 0 (jan 1, 4713 BC)
  D = 365.25xC
  //days for the number of months + 1
  E = (B-D)/30.6001
  //number of months + 1
  F = 30.6001xE
  //days since the start of this year
  Day of month = B-D-F
  Month = E-1 or E-13 (must get number less than or equal to 12)
  Year = C-4715 (if Month is January or February) or C-4716 (otherwise)

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now