Greetings! I have this problem encountered and I need to finish this as my home work. My assignment is all about date functioning. I need to get the number of weeks from the specific date to current date. Using the database MySQL. For example: My database MySQL has from and to column. from: 2011-05-24 to: 2011-07-24 that is for the database record. Now my assignment in PHP part is to calculate how many weeks are their in that range given. I hope you can help me guys. I am totally new to PHP and still learning. I hopr you can help me with this. Thank you, Magina
You could do this within the actual MySQL query, but if you're after a PHP, this should work: First convert the dates to a unix timestamp, minus the start date from the end date and then divide that by the seconds in a week (unix timestamps are based on seconds) and then round the number given. <?php $start = strtotime('24-04-2011'); $end = strtotime('24-05-2011'); echo round(($end - $start) / 604800); PHP: