Jump to content

Select Years and there month Mysql


simzam

Recommended Posts

if you're still designing the DB I would set just one date column, and you can use MySQL's YEAR() and MONTH() functions. You can also use these functions with unix timestamps

 

If not, how are the columns currently set? What type are they, INTEGER, VARCHAR, DATE, DATETIME etc? And what values do they hold? i.e. 1 for January, or a unix timestamp??

oh k

 

suppose I'm using column called Date and data-type TIMESTAMP . timestamp store date and time YYYY-MM-DD HH:MM:SS

how could i select  2009 months how to use query actually i want to display years and there child nodes months but it should selected from from database.

and how to select year and month from time-stamp using php

 

like 2009 months

jan

feb

 

2010

jan

feb

to sort it into years then months you would just have an order by clause in the SQL query such as

select etc etc FROM ..... 
ORDER BY YEAR(dateColumn) DESC, MONTH(dateColumn) ASC

 

 

And then if you want a mysql to display the month/year in human readable terms

SELECT DATE_FORMAT(dateColumn, '%M %Y') AS yearMonth ... from table etc

[code=php:0]

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.