simzam Posted December 22, 2010 Share Posted December 22, 2010 Hi guyz i have database that contains Year column and there month column i want to select year and following month +2006 - jan - april +2007 - jan - april Link to comment https://forums.phpfreaks.com/topic/222362-select-years-and-there-month-mysql/ Share on other sites More sharing options...
joel24 Posted December 22, 2010 Share Posted December 22, 2010 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 https://forums.phpfreaks.com/topic/222362-select-years-and-there-month-mysql/#findComment-1150233 Share on other sites More sharing options...
simzam Posted December 22, 2010 Author Share Posted December 22, 2010 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 https://forums.phpfreaks.com/topic/222362-select-years-and-there-month-mysql/#findComment-1150245 Share on other sites More sharing options...
joel24 Posted December 22, 2010 Share Posted December 22, 2010 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 https://forums.phpfreaks.com/topic/222362-select-years-and-there-month-mysql/#findComment-1150516 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.