Page 1 of 1

Counting by months not days

Posted: Sat Oct 27, 2007 11:20 am
by SirChick
I have a script that i want to alter to count how many months old something is rather than days, at the moment its going by days old > 6 rather than months.. this is what i got but i dont know how to alter it :

Code: Select all

<?
//get last event date and now date
$GetDate = mysql_query("SELECT DATEDIFF(NOW(), FieldUpdate) AS MonthsOld FROM countries 
					WHERE  CountryID='1'")
					or die(mysql_error());
$monthsoldrow = mysql_fetch_assoc($GetDate);

//if its been 6 months echo the secret button
If ($monthsoldrow >6){
Echo'
<input type="submit" id="Button1" name="Button1" value="Update" style="position:absolute;left:667px;top:180px;width:75px;height:24px;z-index:20">
';
}
?>
Could some one help me with this please :D thankyou.

Posted: Sat Oct 27, 2007 12:55 pm
by RobertGonzalez

Code: Select all

If ($monthsoldrow['MonthsOld'] >6)

Posted: Sat Oct 27, 2007 12:56 pm
by RobertGonzalez
PS Moved to PHP - Code since this was code, not SQL.

Posted: Sat Oct 27, 2007 1:07 pm
by feyd
DATEDIFF() returns number of days, not months. This is a problem for SQL to do. ;)

Posted: Sat Oct 27, 2007 4:04 pm
by califdon
One issue is how you define "months old". Do you count it as from the day in one month to the same day in the other month? In other words, if the first date was July 31 and the second date was Feb. 28, would that be 6 or 7 months?? Or do you count it as the difference in days to the nearest month?? Or do you count it as the number of full months between two dates?? You might have to write a custom function to give you such a result.