anser316 Posted March 24, 2008 Share Posted March 24, 2008 I have a problem with showing rows of data from MYSQL to pHP that have the date of the current month, previous month, current year and previous year. i want to show on the following php forms. i just would like to know how to match the month or year, or get previous month or year, functions E.G. MYSQL ID DATE 01 2008-3-12 02 2008-3-10 03 2008-2-10 04 2008-2-9 05 2007-11-9 06 2007-02-8 i want to show on the following php forms CURRENT MONTH FORM PREVIOUS MONTH FORM CURRENT YEAR FORM PREVIOUS YEAR FORM 01 2008-3-12 03 2008-2-10 01 2008-3-12 06 2007-02-8 02 2008-3-10 04 2008-2-9 02 2008-3-10 03 2008-2-10 04 2008-2-9 Link to comment https://forums.phpfreaks.com/topic/97621-problem-with-dates-months/ Share on other sites More sharing options...
cooldude832 Posted March 24, 2008 Share Posted March 24, 2008 simple way to convert MySQL DateTime <?php $date = date("m-d-y", strtotime($MYSQL_DATE_VAR)); Link to comment https://forums.phpfreaks.com/topic/97621-problem-with-dates-months/#findComment-499486 Share on other sites More sharing options...
anser316 Posted March 24, 2008 Author Share Posted March 24, 2008 this is the code i have so far, after i connect to the mysql $result =mysql_query("SELECT id,date FROM date"); echo "<br><br>"; echo "<B>Current Month</B><p>"; echo "<table border='1'>"; echo "<tr> <th>ID</th> <th>Date</th></tr>"; while($row = mysql_fetch_array( $result )) { echo "<tr><td>"; echo $row['id']; echo "</td><td>"; echo $row['date']; echo "</td></tr>"; } echo "</table>"; Link to comment https://forums.phpfreaks.com/topic/97621-problem-with-dates-months/#findComment-499492 Share on other sites More sharing options...
anser316 Posted March 24, 2008 Author Share Posted March 24, 2008 please can someone help Link to comment https://forums.phpfreaks.com/topic/97621-problem-with-dates-months/#findComment-499524 Share on other sites More sharing options...
anser316 Posted March 24, 2008 Author Share Posted March 24, 2008 i can now display data from current month and year, but still not previous i tried using where month(date) =month(Current_date()-1), but that does not work $result =mysql_query("SELECT id,date FROM date where month(date) =month(Current_date())"); echo "<br><br>"; echo "<B>Current Month</B><p>"; echo "<table border='1'>"; echo "<tr> <th>ID</th> <th>Date</th></tr>"; while($row = mysql_fetch_array( $result )) { echo "<tr><td>"; echo $row['id']; echo "</td><td>"; echo $row['date']; echo "</td></tr>"; } echo "</table>"; Link to comment https://forums.phpfreaks.com/topic/97621-problem-with-dates-months/#findComment-499575 Share on other sites More sharing options...
anser316 Posted March 24, 2008 Author Share Posted March 24, 2008 I HAVE NOW SOLVED IT BY USING: CURRENT MONTH: WHERE MONTH(presc_date) = MONTH(DATE_ADD(CURDATE(),INTERVAL 0 MONTH)) PREVIOUS MONTH: WHERE MONTH(presc_date) = MONTH(DATE_ADD(CURDATE(),INTERVAL -1 MONTH)) CURRENT YEAR: WHERE YEAR(presc_date) = YEAR(DATE_ADD(CURDATE(),INTERVAL 0 YEAR)) PREVIOUS YEAR: WHERE YEAR(presc_date) = YEAR(DATE_ADD(CURDATE(),INTERVAL -1 YEAR)) Link to comment https://forums.phpfreaks.com/topic/97621-problem-with-dates-months/#findComment-499723 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.