Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Julian Date conversions

Status
Not open for further replies.

goldnhwk

Programmer
Feb 11, 2000
10
0
0
US
Hi -<br>

<br>

does anyone out there know how to convert dates to Julian in QBASIC????<br>

<br>

- Vicki
 
well... it's been so long since I've actually worked in QBASIC :eek:) so I can't remember how to do dates at all... what are you working with so far? What do you have already? There's probably a way to do it that isn't language-specific, I can probably help you if I know where you're at at the moment. <p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href= imotic ::</a><br>
 
Hmmm....I'm not sure on the Julian dates part....not remembering that calendar very well; but if you give me a description of the diff. between Julian & real-world I'm sure I could come up with a little more help for you ;) <p>-Robherc<br><a href=mailto:robherc@netzero.net>robherc@netzero.net</a><br><a href= shared.freeservers.com/searchmaster.html>SearchMaster Interface...11-in-1</a><br>Wanting to learn Assembler; please e-mail me any tutorials or links for it that are useful to you :)
 
2.12. What is the Julian Period?<br>--------------------------------<br><br>The Julian period (and the Julian day number) must not be confused<br>with the Julian calendar. <br><br>The French scholar Joseph Justus Scaliger (1540-1609) was interested<br>in assigning a positive number to every year without having to worry<br>about BC/AD. He invented what is today known as the &quot;Julian Period&quot;.<br><br>The Julian Period probably takes its name from the Julian calendar,<br>although it has been claimed that it is named after Scaliger's father,<br>the Italian scholar Julius Caesar Scaliger (1484-1558).<br><br>Scaliger's Julian period starts on 1 January 4713 BC (Julian calendar)<br>and lasts for 7980 years. AD 1998 is thus year 6711 in the Julian<br>period. After 7980 years the number starts from 1 again.<br><br>Why 4713 BC and why 7980 years? Well, in 4713 BC the Indiction, the Golden Number and the Solar<br>Number were all 1. The next times this happens is<br>15*19*28=7980 years later, in AD 3268.<br><br>Astronomers have used the Julian period to assign a unique number to<br>every day since 1 January 4713 BC. This is the so-called Julian Day<br>(JD). JD 0 designates the 24 hours from noon UTC on 1 January 4713 BC<br>to noon UTC on 2 January 4713 BC.<br><br>This means that at noon UTC on 1 January AD 2000, JD 2,451,545 will<br>start.<br><br>This can be calculated thus:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;From 4713 BC to AD 2000 there are 6712 years.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;In the Julian calendar, years have 365.25 days, so 6712 years<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;correspond to 6712*365.25=2,451,558 days. Subtract from this<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;the 13 days that the Gregorian calendar is ahead of the Julian<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;calendar, and you get 2,451,545.<br><br>Often fractions of Julian day numbers are used, so that 1 January AD<br>2000 at 15:00 UTC is referred to as JD 2,451,545.125.<br><br>Note that some people use the term &quot;Julian day number&quot; to refer to any<br>numbering of days. NASA, for example, use the term to denote the<br>number of days since 1 January of the current year.<br><br><br>2.12.1. Is there a formula for calculating the Julian day number?<br>-----------------------------------------------------------------<br><br>Try this one (the divisions are integer divisions, in which remainders<br>are discarded):<br><br>&nbsp;&nbsp;&nbsp;a = (14-month)/12<br>&nbsp;&nbsp;&nbsp;y = year+4800-a<br>&nbsp;&nbsp;&nbsp;m = month + 12*a - 3<br><br>&nbsp;&nbsp;For a date in the Gregorian calendar:<br>&nbsp;&nbsp;&nbsp;JDN = day + (153*m+2)/5 + y*365 + y/4 - y/100 + y/400 - 32045<br><br>&nbsp;&nbsp;For a date in the Julian calendar:<br>&nbsp;&nbsp;&nbsp;JDN = day + (153*m+2)/5 + y*365 + y/4 - 32083<br><br><br>JDN is the Julian day number that starts at noon UTC on the specified<br>date.<br><br>The algorithm works fine for AD dates. If you want to use it for BC<br>dates, you must first convert the BC year to a negative year (e.g.,<br>10 BC = -9). The algorith works correctly for all dates after 4800 BC,<br>i.e. at least for all positive Julian day numbers.<br><br><br>To convert the other way (i.e., to convert a Julian day number, JDN,<br>to a day, month, and year) these formulas can be used (again, the<br>divisions are integer divisions):<br><br>&nbsp;&nbsp;For the Gregorian calendar:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a = JDN + 32045<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b = (4*(a+36524))/146097 - 1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c = a - (b*146097)/4<br><br>&nbsp;&nbsp;For the Julian calendar:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b = 0<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c = JDN + 32083<br><br>&nbsp;&nbsp;Then, for both calendars:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d = (4*(c+365))/1461 - 1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e = c - (1461*d)/4<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m = (5*(e-1)+2)/153<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;day&nbsp;&nbsp;&nbsp;= e - (153*m+2)/5<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;month = m + 3 - 12*(m/10)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;year&nbsp;&nbsp;= b*100 + d - 4800 + m/10<br><br><br>2.12.2. What is the modified Julian day number?<br>-----------------------------------------------<br><br>Sometimes a modified Julian day number (MJD) is used which is<br>2,400,000.5 less than the Julian day number. This brings the numbers<br>into a more manageable numeric range and makes the day numbers change<br>at midnight UTC rather than noon.<br><br>MJD 0 thus started on 17 Nov 1858 (Gregorian) at 00:00:00 UTC.<br>
 
Hey <b>goldnhwk</b>, I've just happened to have gone through my old BASes and came across a few I got off the web.<br><br>And in one of them, I came across the following code (which you should be able to modify to your lit'l heart's content.)<br><br><br><FONT FACE=monospace><b>DECLARE FUNCTION DateToJulian! (Dat$)<br><br><br>FUNCTION DateToJulian! (Dat$)<br>'*******************************************************************************<br>'*&nbsp;&nbsp;converts gregorian-style mm/dd/yyyy date to julian date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*<br>'*******************************************************************************<br>&nbsp;&nbsp;&nbsp;&nbsp;Month% = VAL(MID$(Dat$, 1, 2))<br>&nbsp;&nbsp;&nbsp;&nbsp;Day% = VAL(MID$(Dat$, 4, 2))<br>&nbsp;&nbsp;&nbsp;&nbsp;Year% = VAL(MID$(Dat$, 7, 4))<br><br>&nbsp;&nbsp;&nbsp;&nbsp;SELECT CASE Month%<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CASE IS &gt; 2<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Month% = Month% - 3<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CASE IS &lt;= 2<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Month% = Month% + 9<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Year% = Year% - 1<br>&nbsp;&nbsp;&nbsp;&nbsp;END SELECT<br><br>&nbsp;&nbsp;&nbsp;&nbsp;A = 146097# * FIX(FIX(Year% / 100) / 4)<br>&nbsp;&nbsp;&nbsp;&nbsp;B = FIX(1461# * (Year% MOD 100) / 4)<br>&nbsp;&nbsp;&nbsp;&nbsp;C = FIX((153# * Month% + 2) / 5) + Day% + 1721119<br><br>&nbsp;&nbsp;&nbsp;&nbsp;DateToJulian = A + B + C<br><br>END FUNCTION</b></font><br><br>This may help I'm sure.&nbsp;&nbsp;Especially since you don't have to type it all in.<br><br>Just cut and paste away like me.<br>I'm MiggyD (HEY THAT RHYMES, WHAT DO YA KNOW!?!?)<br><br><i>[Note--couldn't resist the rhyming thing there.]</i> <p> <br><a href=mailto: > </a><br><a href= > </a><br>If a tree falls in the forest and there's no one around, does it make sound? Its not the sound that matters, but the silence it leaves behind.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top