[solved] selecting certain months

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

[solved] selecting certain months

Post by Nay »

Okay, I asked this question ealier before and got it but now I'm using a different approach for the date. I have a MySQL timestamp, and I want to select the months from it.

Before:

Code: Select all

news | date | month | comments

yay!  | 9-11 | jan     |  none
yay!  | 9-11 | jul     |  none
yay!  | 9-11 | dec     |  none
then I could do a:

Code: Select all

select distinct month from news
but now i have the timestamp for the date:

Code: Select all

news | date                | comments

yay!  | 121020031155 |  none
yay!  | 111220031155 |  none
yay!  | 101120031155 |  none
i tried to:

Code: Select all

SELECT DATE_FORMAT( date, '%m-%y' ) AS formatted_date DISTINCT formatted_date
FROM news
but that threw up an error when i tried it in phpmyadmin. any ideas?

thanks,

-Nay
Last edited by Nay on Mon Nov 24, 2003 1:31 am, edited 1 time in total.
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

i dn't have any dates like that, but it's called idate.

maybe this will help :

http://www.mysql.com/doc/en/Using_DATE.html

i'd also look up on google for idate conversions
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Hey, thanks for the helpy link. I always forget to check with mysql.com O_o. Anyhow, I've got it solved:

Code: Select all

SELECT DISTINCT DATE_FORMAT(date, '%M %Y') AS formatted_date ORDER BY formatted_date ASC
-Nay
Post Reply