Solved

Given Julian Date - What Month & Day?

Posted on 1998-09-11
2
674 Views
Last Modified: 2008-03-10
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
Comment
Question by:awd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1172563
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
 

Accepted Solution

by:
AlanB082898 earned 50 total points
ID: 1172564
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

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question