Division issues

I have the following function below

function average ($year)
{
$start = "".$year."-01-01";
$finish = "".$year."-12-12";
$av = between ($finish,$start);
echo $av / 12;
}

$av will return the following value = 42846 as a string

When the above function runs it returns a value of 428460

can any one help me please?

PHP does not define a function “between”. So without knowing what that does, we cant answer your question.

On a slightly off-topic thing, is there a reason why you only average to December 12th, rather than to the 31st? Also, I can’t see how that function returns anything, all it does is echo the value.

1 Like

It looks like you want to manage dates (and maybe times), you might want to look into using php built-in functions(methods) instead of making your own. It would save your time and should be easier.

For example:

<?php
function number_of_days($date) {
	$today = new DateTime();
	$future = new DateTime($date);
	
	$difference = $future->diff($today, true);
	echo "There are " . $difference->days . " days till the Detroit Tigers opening day!";
}

number_of_days("2015-04-06 13:08:00");

i removed the echo and done the return and it has resolved it :slight_smile:
Happy days! the dates are UTC.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.