timmah1 Posted April 30, 2009 Share Posted April 30, 2009 I'm trying to break down sales on a monthly basis. I want to show information for each month. So, right now I'm trying to grab everything from the database where the field 'purchase'(month) equals May (05) The purchase field type is DATE Here is what I have, and it is not working correctly $month = "05"; $sql3 = "SELECT * FROM affiliates1 WHERE purchase = '".date("m", strtotime($month))."' AND affil_id = '$code'"; How can I accomplish this? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/156252-solved-grab-info-based-on-month/ Share on other sites More sharing options...
the182guy Posted April 30, 2009 Share Posted April 30, 2009 If you're using MySQL you can use the MySQL function DATE_FORMAT() to achieve the desired results. For example, $month = "05"; $sql3 = "SELECT * FROM affiliates1 WHERE DATE_FORMAT(purchase, '%m') = '$month' AND affil_id = '$code'"; Link to comment https://forums.phpfreaks.com/topic/156252-solved-grab-info-based-on-month/#findComment-822566 Share on other sites More sharing options...
timmah1 Posted April 30, 2009 Author Share Posted April 30, 2009 Perfect! Thank you 182 Link to comment https://forums.phpfreaks.com/topic/156252-solved-grab-info-based-on-month/#findComment-822570 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.