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??

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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]

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.