Solved

Given Julian Date - What Month & Day?

Posted on 1998-09-11
2
665 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
2 Comments
 
LVL 84

Expert Comment

by:ozo
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now