Solved

Given Julian Date - What Month & Day?

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SendMessage fails while PostMessage works 2 114
C Language combined operators 28 109
C++ finding a sting in a char* string from a text file 3 108
Path to  STL Map header file 1 58
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 …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 clear a vector as well as how to detect empty vectors in C++.

770 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