phpmady Posted September 23, 2010 Share Posted September 23, 2010 Hi, I am having set of records, id name dob 1 philip 1278226800 2 winsent 1278216800 3 Benn 1272226800 now i want to fetch the records based on the month and listing out, can anyone help me to write for the above concept. Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/214195-how-to-get-the-month-in-the-date-in-set-of-records/ Share on other sites More sharing options...
Chris92 Posted September 23, 2010 Share Posted September 23, 2010 http://php.net/date echo date("F", $row['dob']); Quote Link to comment https://forums.phpfreaks.com/topic/214195-how-to-get-the-month-in-the-date-in-set-of-records/#findComment-1114517 Share on other sites More sharing options...
Pikachu2000 Posted September 23, 2010 Share Posted September 23, 2010 Can you clarify that a little? Do you mean you want to list all the records, grouped or ordered by the month, or you want to list the records that are from a particular month? Quote Link to comment https://forums.phpfreaks.com/topic/214195-how-to-get-the-month-in-the-date-in-set-of-records/#findComment-1114528 Share on other sites More sharing options...
phpmady Posted September 23, 2010 Author Share Posted September 23, 2010 Can you clarify that a little? Do you mean you want to list all the records, grouped or ordered by the month, or you want to list the records that are from a particular month? Hi, First of all Thanks for your reply, i want to list the records that are from a particular month thanks, Quote Link to comment https://forums.phpfreaks.com/topic/214195-how-to-get-the-month-in-the-date-in-set-of-records/#findComment-1114545 Share on other sites More sharing options...
PFMaBiSmAd Posted September 23, 2010 Share Posted September 23, 2010 Use the msyql MONTH() function directly in your query. You will need to get the Unix Timestamp into a usable DATE format (why do people still bother to use a Unix Timestamp.) See the mysql FROM_UNIXTIME() function to do that. Untested but should work - $month = 9; // the month you want to find $query = "SELECT * FROM your_table WHERE MONTH(FROM_UNIXTIME(your_Unix_Timestamp_column)) = $month"; If you want the current month, you could do that directly in the query - $query = "SELECT * FROM your_table WHERE MONTH(FROM_UNIXTIME(your_Unix_Timestamp_column)) = MONTH(CURDATE())"; Quote Link to comment https://forums.phpfreaks.com/topic/214195-how-to-get-the-month-in-the-date-in-set-of-records/#findComment-1114559 Share on other sites More sharing options...
Pikachu2000 Posted September 23, 2010 Share Posted September 23, 2010 I don't store UNIX timestamps, so I haven't tested this, but it should work, as far as I can tell. $month = 5; // query is set up for numeric month representation . . . $query = "SELECT `field_1`, `field_2` FROM `table` WHERE FROM_UNIXTIME(`timestamp_field`, '%m') = $month"; Quote Link to comment https://forums.phpfreaks.com/topic/214195-how-to-get-the-month-in-the-date-in-set-of-records/#findComment-1114561 Share on other sites More sharing options...
phpmady Posted September 23, 2010 Author Share Posted September 23, 2010 Use the msyql MONTH() function directly in your query. You will need to get the Unix Timestamp into a usable DATE format (why do people still bother to use a Unix Timestamp.) See the mysql FROM_UNIXTIME() function to do that. Untested but should work - $month = 9; // the month you want to find $query = "SELECT * FROM your_table WHERE MONTH(FROM_UNIXTIME(your_Unix_Timestamp_column)) = $month"; If you want the current month, you could do that directly in the query - $query = "SELECT * FROM your_table WHERE MONTH(FROM_UNIXTIME(your_Unix_Timestamp_column)) = MONTH(CURDATE())"; Thanks, Thanks i have made it using your query, and thanks for make me knowledgable in date functions. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/214195-how-to-get-the-month-in-the-date-in-set-of-records/#findComment-1114568 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.