Jump to content

Julian date


jetlife76

Recommended Posts

Hi guys, i am writing a script for a program to calculate the julian date of a date the user inputs from a front form. So far my code shows the julian date without using a php function. I need to understand how to use the gregorianToJd function in php. If anyone has any suggestions feel free to give me your input.

Link to comment
https://forums.phpfreaks.com/topic/255530-julian-date/
Share on other sites

Here's what i have, If u wanna take a look


<?php
$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"Date:$monthname[$months] $days, $years<br>";

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

if ($years % 4 == 0) {

	//Divisible by 4 but not 100
	if ($years % 100 != 0) {
	echo "<br>$years is a leap year.";
	}
	//Divisible by 4 and 100 and 400
	else if ($years % 400 == 0) {
	echo "<br>$years is a leap year.";
	}
	//4 and 100 but not 400
	else {
	echo "<br>$years is not a leap year.";
	}
}
// It is not divisible by 4.
else {
	echo "<br>$years is not a leap year.";
}
	            
?>

Link to comment
https://forums.phpfreaks.com/topic/255530-julian-date/#findComment-1310071
Share on other sites

Ok i figured out how to get the function to work. But my issue now is adjusting to Leap years. Here's what i have now.


<?php
$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');

$monthnum=array( 'Jan'=>'1', 'Feb'=>'2', 'Mar'=>'3', 
'Apr'=>'4', 'May'=>'5', 'Jun'=>'6', 'Jul'=>'7', 
'Aug'=>'8', 'Sep'=>'9', 'Oct'=>'10', 'Nov'=>'11', 'Dec'=>'12');	

print"Date:$monthname[$months] $days, $years<br>";
$JulianDate=$monthdays[$months] + $days;
$jdate = gregoriantojd($monthnum[$months], $days, $years) - gregoriantojd(1,1,$years) + 1;
//if ($years < 2012) {
	//$jdate++;}
print "Calculated without using a PHP Function:$JulianDate";
print "<br>Calculated using a PHP Function:$jdate";
if ($years % 4 == 0) {

	//Divisible by 4 but not 100
	if ($years % 100 != 0) {
	echo "<br>$years is a leap year.";
	}
	//Divisible by 4 and 100 and 400
	else if ($years % 400 == 0) {
	echo "<br>$years is a leap year.";
	}
	//4 and 100 but not 400
	else {
	echo "<br>$years is not a leap year.";
	}
}
// It is not divisible by 4.
else {
	echo "<br>$years is not a leap year.";
}
	            
?>

Link to comment
https://forums.phpfreaks.com/topic/255530-julian-date/#findComment-1310458
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.