Thanks for the reply but now I need to use PHP and mysql to get the sum of the amounts on a particular quater, using the loop.
You can limit your results using the WHERE clause in your MySQL query, which is perfectly accessible in PHP.
If you absolutely have to work with every single (unsorted) record in the database at once, and there's absolutely nothing you can do about it, you'll have to use
strtotime to convert the dates into Unix timestamps.