It worked before PHP was updated to the newer version, I have searched and read about a million other date related problems on different forums including this one... I must be looking in the wrong place or something 'cause I can't figure out why it won't give me the right difference between dates...I think it must not be getting the right starting time but my pathetic attempts to fix this haven't helped!

<?


function dow($dd,$mm,$yy)
{
	$res=($yy+(int)($yy-1)/4-(int)($yy-1)/100+(int)($yy-1)/400+julianday($dd,$mm,$yy))%7;
	if($res==1)
		$res="Sunday";
	elseif($res==2)
		$res="Monday";
	elseif($res==3)
		$res="Tuesday";
	elseif($res==4)
		$res="Wednesday";
	elseif($res==5)
		$res="Thursday";
	elseif($res==6)
		$res="Friday";
	else
		$res="Saturday";	
	return($res);
}
function julianday($dd,$mm,$yy)
{
	$days=array(31,0,31,30,31,30,31,31,30,31,30,31);
	$days[1]=$yy%4==0&&$yy%100!=0||$yy%400==0?29:28;
	for ($i=1;$i<$mm;$i++)
		$jd=$jd+$days[$i-1];
	return($jd+$dd);
}
function age($dd,$mm,$yy)
{
	$now=split("-",date("d-m-Y"));
	$dd1=$now[0];
	$mm1=$now[1];
	$yy1=$now[2];
	if($yy1==$yy)
	{
		$age["years"]=0;
		$age["days"]=julianday($dd1,$mm1,$yy1)-julianday($dd,$mm,$yy);
		return($age);
	}
	else
	{
	$ans1=$yy%4==0&&$yy%100!=0||$yy%400==0?366-julianday($dd,$mm,$yy):365-julianday($dd,$mm,$yy);
		$ans2=julianday($dd1,$mm1,$yy1);
		$sy=$yy+1;
		$ly=$yy1-1;
		while($sy++<=$ly)
			$sum=$sy%4==0&&$sy%100!=0||$sy%400==0?$sum+366:$sum+365;
	}
	$years=(float)($sum+$ans1+$ans2)/365;
	$days=($years-(int)($years))*365;
	$age[years]=(int)$years;
	$age[days]=(int)$days;
	return ($age);
} 
?>

<table width="90%"><tr><td class="g" colspan="4" style="text-align:center;">Find out how much time has elapsed since your special date</td></tr>
<tr><td class="center"><form method="post" action="http://www.atimealone.com/HowLong.php" />Enter Date </td>
<td class="center">
<input size="14" name="dob"  value="format dd/mm/yyyy"  onfocus="if(this.value=='format dd/mm/yyyy')this.value='';" onblur="if(this.value=='')this.value='format dd/mm/yyyy';" /></td>
<td class="center"><select name="day">
<option selected="selected" value="'re difference: ">Select one</option>
<option value="'ve been together">Anniversary</option>
<option value="'ve been alive">Birthday</option>
<option value="'ve been working">Seniority Day</option>
<option value="'ve been sober">Sobriety Day</option>
<option value="'re difference: ">Other</option></select>
</td><td><input type="submit" /></td></tr></table>

<?
if($dob)
 extract($_REQUEST);
{
	$dob=str_replace(" ","",$dob);
	if(!ereg("^[0-9]{1,2}(-|/)[0-9]{1,2}(-|/)[0-9]{4}$",$dob))
		$msg="Invalid date";
	elseif(ereg("^[0-9]{1,2}/[0-9]{1,2}/[0-9]{4}",$dob))
		$dob=split("/",$dob);
	else
		$dob=split("-",$dob);
	if($msg) die($msg);
	$dd=$dob[0];
	$mm=$dob[1];
	$yy=$dob[2];
	$age=age($dd,$mm,$yy);
    $day=stripslashes ($day);
	echo "<div class='b' style='text-align:center;'>The date you entered is $dd/$mm/$yy<br />";
	echo "The weekday was " . dow($dd,$mm,$yy) . "<br />";
	echo "You$day $age[years] years and $age[days] days.<br />";
}
?>

    just one idea: you're doing an extract(), but this is AFTER you check
    $dob for content,
    maybe you want to check it like this:

    if ($_POST['dob'])
    {
      ...

    what's the result anyway? just garbage? always the same? constantly wrong value?

      I'll try that - as for the results, I thought They were constantly a certain number of days off, but I was wrong, it seems random...anyway here's the link to where the script is screwing up:

      http://www.atimealone.com/HowLong.php

      edit - I don't know what's going on now! It was giving dates last night, now it just says invalid date, with or without your change, sh*t!

      I gotta go to the dentist, I'll be back in a couple hours, Thanks for trying, though, sorry I have to run out on ya...

        since you're using only one variable replace the extract() with
        $dob = $_POST['dob'];

        and print out $dob for debugging to see whether it's passed

        (hope your visit to the dentist wasn't too painful 😃 )

          'twas just an exam - the only pain involved - leaving the computer! Thanks for the good wishes!

          Ok, It's now echoing out $dob and it is the same thing I input... Here's the last bit of code as it is now:

          <?
          if ($_POST['dob'])
          $dob = $_POST['dob'];
          $day = $_POST['day'];
          	echo "dob = ".$dob; 
          
          {
          
          $dob=str_replace(" ","",$dob);
          if(!ereg("^[0-9]{1,2}(-|/)[0-9]{1,2}(-|/)[0-9]{4}$",$dob))
          	$msg="Invalid date";
          elseif(ereg("^[0-9]{1,2}/[0-9]{1,2}/[0-9]{4}",$dob))
          	$dob=split("/",$dob);
          else
          	$dob=split("-",$dob);
          if($msg) die($msg);
          $dd=$dob[0];
          $mm=$dob[1];
          $yy=$dob[2];
          $age=age($dd,$mm,$yy);
          $day=stripslashes ($day);
          echo "<div class='b' style='text-align:center;'>The date you entered is $dd/$mm/$yy<br />";
          echo "The weekday was " . dow($dd,$mm,$yy) . "<br />";
          echo "You$day $age[years] years and $age[days] days.<br /></div>";
          }
          ?>
          

          The date difference is spitting out consistantly random crap
          the same wrong difference for the same date, for instance, if I enter 05/30/1951 it prints out that the diference is 51 years and 148 days every time, if I enter todays date it says 0 years and -228 days every time, if I put in 01/06/1969 I get 33 years and 363 days every time so not being a math major, I don't see a pattern, but I think since it's always the same for the same date there must be a set pattern to it. edit - I just noticed I have been using the wrong date format on one date, although I clearly show which date format is valid on the form! Duh! But even when I use the right format there is garbage coming out... 30/05/1951 gets "You've been alive 52 years and 3 days." which is obviously wrong.

          Edit again - OK, I'll go away now and wait for someone on second shift to get bored enough to maybe look at this code, Thanks for your help so far!

          another update: this script is in the snippit library, was originally put there by nageshyd.

            Write a Reply...