Julian Date Calculator

can't get leap year function correct.need help also with figuring

Page 1 of 1

11 Replies - 6587 Views - Last Post: 23 August 2008 - 11:58 AM Rate Topic: -----

#1 lucydinner  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 20-August 08

Julian Date Calculator

Post icon  Posted 21 August 2008 - 01:02 AM

<html>
<head> <title>Program 10 Julian Date Calculator</title> </head>
<body>
<?php
// Teresa Roberson
// PHP -Program10a
//August 18, 2008
?> 
<form name="input" action="Program10b.php" method="post">
<h1><font color="purple">Julian Date Calculator</font></h1>

<br>
<font color="purple" size=4>Select Month:</font>
<select name="months">
<option>Jan</option>
<option>Feb</option>
<option>Mar</option>
<option>Apr</option>
<option>May</option>
<option>Jun</option>
<option>Jul</option>
<option>Aug</option>
<option>Sept</option>
<option>Oct</option>
<option>Nov</option>
<option>Dec</option>
</select>
<br><br>
<?php
print "<font color=purple size=4>Select Day:</font>";
print '<select name="day">';
for ($i=1; $i<32; $i++){
print "<option>$i</option>";
}
print '</select>'
?>
<br><br>
<font color="purple" size=4>Enter Year:</font><input type="num" size="4" name="years"></font>

<br><br><br><input type="submit" value="Click To Submit">
<input type="reset" value="Erase and Restart"></center>

</form>
</body> 
</html>
<html>
<head> <title>Program 10b Julian Date Calculator Results </title> </head>
<body>
 <br></font>
<?php
// Teresa Roberson
// PHP -Program10b
//August 18, 2008
$months = $_POST['months'];
$days = $_POST['day'];
$years = $_POST['years'];
//associative array for Julian Date
$monthdays=array( 'Jan'=>0, 'Feb'=>31, 'Mar'=>59, 
	'Apr'=>90, 'May'=>120, 'Jun'=>151, 'Jul'=>181, 'Aug'=>212,
	'Sep'=>243, 'Oct'=>273, 'Nov'=>304, 'Dec'=>334);

$monthname=array( 'Jan'=>'January', 'Feb'=>'Febuary', 'Mar'=>'March', 
	'Apr'=>'April', 'May'=>'May', 'Jun'=>'June', 'Jul'=>'July', 
	'Aug'=>'August', 'Sep'=>'September', 'Oct'=>'October', 'Nov'=>'November', 'Dec'=>'December');

print "<h2><font color=green size=4>Three Digit Julian Date Calculator</h2><br>";
print"Date:$monthname[$months] $days, $years<br>";

$mJulianDate=$monthdays[$months] + $days;
	print "Calculated without using a PHP Function:$mJulianDate";

$leapyear=date('L', mktime(0,0,0, $monthdays[$months],1, $years));
If ($leapyear >0){
	If ($month!='Jan'||!='Feb'){
		$mJulianDate=$mJulianDate + 1
		Print" Leap year=yes";
	}else{
		Print "Leap year=no";
	}
}
?> 
</body> 
</html>



Is This A Good Question/Topic? 0
  • +

Replies To: Julian Date Calculator

#2 pemcconnell  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 54
  • View blog
  • Posts: 472
  • Joined: 05-August 08

Re: Julian Date Calculator

Posted 21 August 2008 - 04:48 AM

Allo :)

Not 100% sure what you want it to do, but I fixed the syntax errors for you.

<html>
<head> <title>Program 10 Julian Date Calculator</title> </head>
<body>
<?php
// Teresa Roberson
// PHP -Program10a
//August 18, 2008
?> 
<form name="input" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<h1><font color="purple">Julian Date Calculator</font></h1>

<br>
<font color="purple" size=4>Select Month:</font>
<select name="months">
<option>Jan</option>
<option>Feb</option>
<option>Mar</option>
<option>Apr</option>
<option>May</option>
<option>Jun</option>
<option>Jul</option>
<option>Aug</option>
<option>Sept</option>
<option>Oct</option>
<option>Nov</option>
<option>Dec</option>
</select>
<br><br>
<?php
echo "<font color=purple size=4>Select Day:</font>";
echo '<select name="day">';
for ($i=1; $i<32; $i++){
echo "<option>$i</option>";
}
echo '</select>'
?>
<br><br>
<font color="purple" size=4>Enter Year:</font><input type="num" size="4" name="years"></font>

<br><br><br><input type="submit" value="Click To Submit">
<input type="reset" value="Erase and Restart"></center>

</form>
</body> 
</html>
<html>
<head> <title>Program 10b Julian Date Calculator Results </title> </head>
<body>
<br></font>
<?php
// Teresa Roberson
// PHP -Program10b
//August 18, 2008
$months = $_POST['months'];
$days = $_POST['day'];
$years = $_POST['years'];
//associative array for Julian Date
$monthdays=array( 'Jan'=>0, 'Feb'=>31, 'Mar'=>59, 
	'Apr'=>90, 'May'=>120, 'Jun'=>151, 'Jul'=>181, 'Aug'=>212,
	'Sep'=>243, 'Oct'=>273, 'Nov'=>304, 'Dec'=>334);

$monthname=array( 'Jan'=>'January', 'Feb'=>'Febuary', 'Mar'=>'March', 
	'Apr'=>'April', 'May'=>'May', 'Jun'=>'June', 'Jul'=>'July', 
	'Aug'=>'August', 'Sep'=>'September', 'Oct'=>'October', 'Nov'=>'November', 'Dec'=>'December');

print "<h2><font color=green size=4>Three Digit Julian Date Calculator</h2><br>";
print"Date:$monthname[$months] $days, $years<br>";

$mJulianDate=$monthdays[$months] + $days;
	print "Calculated without using a PHP Function:$mJulianDate";

$leapyear=date('L', mktime(0,0,0, $monthdays[$months],1, $years));
if ($leapyear >0){
	if ($month!=('Jan'||'Feb')){ //  Error was here. Origional was -> if ($month!='Jan'||!='Feb'){
		$mJulianDate++;
		echo" Leap year=yes";
	}else{
		echo "Leap year=no";
	}
}
?> 
</body> 
</html>


Was This Post Helpful? 0
  • +
  • -

#3 JBrace1990  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 109
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: Julian Date Calculator

Posted 22 August 2008 - 12:00 AM

i think he's looking for something like : $year%4.... >_>
Was This Post Helpful? 0
  • +
  • -

#4 pemcconnell  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 54
  • View blog
  • Posts: 472
  • Joined: 05-August 08

Re: Julian Date Calculator

Posted 22 August 2008 - 01:09 AM

ahh, get'cha now.

Yeah, the snippet JBrace entered will do the job.

Test it with something like this:

for($i = 2000; $i < 2020; $i++){
	  echo 'The year '.$i.' AD is ';
	  if($i%4!=0){
		   echo ' not ';
	 }
	 echo 'a leap year.<br />';
}


This post has been edited by pemcconnell: 22 August 2008 - 01:11 AM

Was This Post Helpful? 0
  • +
  • -

#5 kummu4help  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 245
  • Joined: 05-August 08

Re: Julian Date Calculator

Posted 22 August 2008 - 03:32 AM

Hi,
i found some good code to determine leap year logic in the following url..
clickhere

if (theYear % 4 == 0) {

		// Is theYear Divisible by 4 but not 100?
		if (theYear % 100 != 0) {
		System.out.println(theYear + " is a leap year.");
		}
		// Is theYear Divisible by 4 and 100 and 400?
		else if (theYear % 400 == 0) {
		System.out.println(theYear + " is a leap year.");
		}
		// It is Divisible by 4 and 100 but not 400!
		else {
		System.out.println(theYear + " is not a leap year.");
		}
	}
	// It is not divisible by 4.
	else {
		System.out.println(theYear + " is not a leap year.");
	}




the reasoning is as follows...

Quote

/**
* LeapYear.java -
* Given a year it is calculated if that year
* is a leap year. Leap year calculation was
* one of the big issues in the Y2K problem.
*
* The specific rules for determining leap years are:
*
* 1) If a year is divisible by 4 it is a
* leap year if #2 does not apply.
* 2) If a year is divisible by 100 it is
* not a leap year unless #3 applies.
* 3) If a year is divisible by 400 it is
* a leap year.
*
* Many programs are believed to have incorrect
* logic for computing leap years due to the
* omission of #2 and/or #3.
*

Was This Post Helpful? 0
  • +
  • -

#6 JBrace1990  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 109
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: Julian Date Calculator

Posted 22 August 2008 - 08:32 AM

ok... by reading the above... why is every 4th year a leap year except if it's only divisible by 400 and not 100?

for that matter, if 1900 wasn't a leap year, and it's every 4 years.... what year was? ?_? or did we just go like 8 years without it? D=
Was This Post Helpful? 0
  • +
  • -

#7 pemcconnell  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 54
  • View blog
  • Posts: 472
  • Joined: 05-August 08

Re: Julian Date Calculator

Posted 22 August 2008 - 08:50 AM

damned solarsystem!
Was This Post Helpful? 0
  • +
  • -

#8 JBrace1990  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 109
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: Julian Date Calculator

Posted 22 August 2008 - 03:46 PM

i know we're way off topic here... but seriously, when is the leap year then? 1900 should have been a leap year, and I think it is... same with 2100
Was This Post Helpful? 0
  • +
  • -

#9 kummu4help  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 245
  • Joined: 05-August 08

Re: Julian Date Calculator

Posted 22 August 2008 - 09:13 PM

hi jbrace ,
i found some explanation for ur doubt. Just read the following quote or go n check following
link in wikipedia

Quote

In the Gregorian calendar, the current standard calendar in most of the world, most years whose division by 4 equals an integer are leap years. In each leap year, the month of February has 29 days instead of 28. Adding an extra day to the calendar every four years compensates for the fact that a solar year is almost 6 hours longer than 365 days.

However, some exceptions to this rule are required since the duration of a solar year is slightly less than 365.25 days. Years that are evenly divisible by 100 are not leap years, unless they are also evenly divisible by 400, in which case they are leap years.[1][2] For example, 1600 and 2000 were leap years, but 1700, 1800 and 1900 were not in the 1582 papal bull (the 1750 British Calendar Act ignores 1700). Similarly, 2100, 2200, 2300, 2500, 2600, 2700, 2900, and 3000 will not be leap years, but 2400 and 2800 will be. By this rule, the average number of days per year will be 365 + 1/4 − 1/100 + 1/400 = 365.2425, which is 365 days, 5 hours, 49 minutes, and 12 seconds.

The Gregorian calendar was designed to keep the vernal equinox on or close to March 21, so that the date of Easter (celebrated on the Sunday after the 14th day of the Moon (i.e. a full moon) that falls on or after 21 March) remains correct with respect to the vernal equinox.[3] The vernal equinox year is about 365.242374 days long (and increasing), whereas the average year length of the Gregorian calendar is 365.2425.

The marginal difference of 0.000125 days means that in around 8,000 years, the calendar will be about one day behind where it is now. But in 8,000 years, the length of the vernal equinox year will have changed by an amount that cannot be accurately predicted (see below). Therefore, the current Gregorian calendar suffices for practical purposes, and Herschel's correction (making 4000 AD not a leap year) will probably not be necessary.

Was This Post Helpful? 0
  • +
  • -

#10 JBrace1990  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 109
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: Julian Date Calculator

Posted 22 August 2008 - 09:55 PM

that still doesn't really answer my question =P
Was This Post Helpful? 0
  • +
  • -

#11 kummu4help  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 245
  • Joined: 05-August 08

Re: Julian Date Calculator

Posted 22 August 2008 - 10:28 PM

They accepted that 2100 is not a leap year
Then what is your doubt...
Was This Post Helpful? 0
  • +
  • -

#12 JBrace1990  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 109
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: Julian Date Calculator

Posted 23 August 2008 - 11:58 AM

if 2100 isn't a leap[ year, and every 4 years it IS a leap year, then when will the leap year be if it's NOT 2100?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1