/    Sign up×
Community /Pin to ProfileBookmark

Grouping query entries by DATE?

Hey everyone.

I’ve got a MySQL database and 2 columns (DATETIME, and Comment). The DATETIME’s are stored in my database like this:

[CODE]2011-04-08 22:09:25[/CODE]

What I am trying to do when I query the database is to group all of the entries together that were made on the same DATE. How do I do this?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@OctoberWindApr 08.2011 — Maybe I don't quite understand what you're trying to do, but
[code=php]
SELECT DATETIME, Comment FROM table GROUP BY DATETIME
[/code]


will sort them by date. You can also call your column as [B]DATE(DATETIME)[/B], which will basically strip out the "time" portion, leaving just the date.
Copy linkTweet thisAlerts:
@GreyfishauthorApr 08.2011 — My original post was a little confusing.

So I queried the database and it returns this information: http://i56.tinypic.com/voyf4k.png

You'll notice that for each row there is a DATE and a comment. So let's say there a couple entries in my database that the have DATES "2011-04-08" and then there are some rows that the have DATE "2011-04-07" and then "2011-04-05", etc.

I would like to be able to separate all of the entries by DATE when I query the database, so that way it will look like this: http://i51.tinypic.com/15o8kex.png
Copy linkTweet thisAlerts:
@GreyfishauthorApr 09.2011 — Any help, anyone?
×

Success!

Help @Greyfish spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...