I have a table 'members' and a column 'date_created'. I want to at any point in time be able to get the number of months between the date_created and the current date. Some should help me out
echo (int)((strtotime("now") - strtotime($date_created)) / (3600 * 24 * 30)); here $date_created would hold your date data.
The above reply will be inaccurate over longer periods because there are not 30 days in every month! This should work better: <?php $date_created = new DateTime('2009-08-28'); $interval = $date_created->diff(new DateTime); printf("Months: %d\n", 12 * $interval->format('%r%y') + $interval->format('%r%m')); // Outputs: // Months: 13 PHP:
How are you defining months, and what should happen with "part" months? There is no need to do this in PHP when MySQL (or any SQL for that matter) provides you with plenty of date/time functions to do this as part of your SELECT from the database.