Hello everyone,
I'm working on a news archive and I'm given the $year and the $month. I have to construct an SQL statement that will query the database and return the days in the given month that have articles posted.
This is the database setup:
[CODE]
id | title | content | date |
1 | So... | Today... | 2006-06-28 12:34:14 |
...
[/CODE]
This is the query I wrote:
SELECT DISTINCT(`date`)
FROM `$tableposts`
WHERE LEFT(`date`,10) >= '$dateBeg' AND
LEFT(`date`,10) <= '$dateEnd'
ORDER BY `date` ASC
LIMIT 32
[SIZE=2]where $dateBeg is first day of month and $dateEnd is last day of month[/SIZE]
What I want to do is:
select distinct days where the truncated datetime field falls within the month's range
I tried the LEFT function but it doesn't work. I want the datetime field to be excluded of the time portion; basically be treated as a DATE field by this query.
Is there a way to achieve this? The next thing after this would be to retrieve all rows from DB and then sort out the duplicates via PHP, though that would be a daunting task though :bemused:
Thanks for your help.