n00b0101
asked on
PHP - Group by month?
Okay, so when I pull data from my table, I'll get (minimally):
start | end | description
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
2009-03-01T09:00:00 | 2009-03-01T11:00:00 | Lorem Ipsum
2009-03-11T09:00:00 | 2009-03-11T12:00:00 | Donec ullamcorper
2009-03-21T09:00:00 | 2009-03-23T09:00:00 | Morbi consectetur
2009-04-05T09:00:00 | 2009-04-07T09:00:00 | Aliquam fringilla
2009-04-17T09:00:00 | 2009-04-17T11:00:00 | Suspendisse consectetur
2009-06-09T09:00:00 | 2009-06-11T09:00:00 | Sed ut nibh a tellus
2009-06-23T09:00:00 | 2009-06-23T12:00:00 | Quisque porta
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
I'm trying to (1) group them by month (2) only show date range when it lasts more than a day (3) not show months that have nothing (i.e., May)
So, the output would look like this:
March 2009
- Lorem Ipsum, 1 March 2009
- Donec ullamcorper, 11 March 2009
- Morbi consectetu, 21 March 2009 to 23 March 2009
April 2009
- Aliquam fringilla, 5 April 2009 to 7 April 2009
- Suspendisse consectetur, 17 April 2009
June 2009
- Sed ut nibh a tellus, 9 June 2009 to 11 June 2009
- Quisque porta, 23 June 2009
I'm getting errors when trying to group by month, and the output of the date is completely wrong. Help!
start | end | description
--------------------------
2009-03-01T09:00:00 | 2009-03-01T11:00:00 | Lorem Ipsum
2009-03-11T09:00:00 | 2009-03-11T12:00:00 | Donec ullamcorper
2009-03-21T09:00:00 | 2009-03-23T09:00:00 | Morbi consectetur
2009-04-05T09:00:00 | 2009-04-07T09:00:00 | Aliquam fringilla
2009-04-17T09:00:00 | 2009-04-17T11:00:00 | Suspendisse consectetur
2009-06-09T09:00:00 | 2009-06-11T09:00:00 | Sed ut nibh a tellus
2009-06-23T09:00:00 | 2009-06-23T12:00:00 | Quisque porta
--------------------------
I'm trying to (1) group them by month (2) only show date range when it lasts more than a day (3) not show months that have nothing (i.e., May)
So, the output would look like this:
March 2009
- Lorem Ipsum, 1 March 2009
- Donec ullamcorper, 11 March 2009
- Morbi consectetu, 21 March 2009 to 23 March 2009
April 2009
- Aliquam fringilla, 5 April 2009 to 7 April 2009
- Suspendisse consectetur, 17 April 2009
June 2009
- Sed ut nibh a tellus, 9 June 2009 to 11 June 2009
- Quisque porta, 23 June 2009
I'm getting errors when trying to group by month, and the output of the date is completely wrong. Help!
Can you please show us the code that is causing the errors?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks for the points! It's a good question and a good opportunity to show how strtotime() and date() work together in ways that are almost magically easy. Best regards, ~Ray
LIKE %2009-03% for March
LIKE %2009-04% for April
and so on