Solved

Given Julian Date - What Month & Day?

Posted on 1998-09-11
2
675 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

615 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