Butterbean Posted January 12, 2015 Share Posted January 12, 2015 (edited) I am looking for a way to have my 'start_date', echo ('start_date' + 1 month). I am looking at the line that reads .... date("F Y",strtotime($row['start_date'])). Does anyone have a suggestion. The date format read, July 2014 or alphabetical full month, numerical full year. Thank you in advance. <?php $query = sqlsrv_query($conn, $sql);if ($query === false){ exit("<pre>".print_r(sqlsrv_errors(), true));}while ($row = sqlsrv_fetch_array($query)){ echo "<tr> <td><a href='view_invoice.php?meter_id=$meter_id&subaccount=$subaccount&start_date=$row[start_date]'>$row[meter_id]</a></td> <td>" . date("F Y",strtotime($row['start_date'])) . "<td>$row[invoice_no]</td><td>" . date_format($row['invoice_date'],'Y-m-d') . "<td>$row[amount_paid]</td>" . "<td>$row[payment_date]</td>" . "<td>$row[check_number]</td>" ;}sqlsrv_free_stmt($query); ?> Edited January 12, 2015 by Butterbean Quote Link to comment https://forums.phpfreaks.com/topic/293861-how-to-echo-a-date-value-as-date-1-month/ Share on other sites More sharing options...
Butterbean Posted January 12, 2015 Author Share Posted January 12, 2015 (edited) Edited January 12, 2015 by Butterbean Quote Link to comment https://forums.phpfreaks.com/topic/293861-how-to-echo-a-date-value-as-date-1-month/#findComment-1502619 Share on other sites More sharing options...
wezhind Posted January 12, 2015 Share Posted January 12, 2015 This should do it. $todayDate = date("Y-m-d"); $dateplusamonth = strtotime(date("Y-m-d", strtotime($todayDate)) . "+1 month"); echo date('F Y', $dateplusamonth); http://php.net/manual/en/function.date.php http://php.net/manual/en/function.strtotime.php Good luck. Quote Link to comment https://forums.phpfreaks.com/topic/293861-how-to-echo-a-date-value-as-date-1-month/#findComment-1502627 Share on other sites More sharing options...
Butterbean Posted January 12, 2015 Author Share Posted January 12, 2015 (edited) Thank you for your help. In this case, 'start_date' is a date that is manually entered into php to query mssql for data. I'm using this start date in addition to this purpose to signify the month the bill was produced (which is at the end the 30 days that was queried by the bill. Unfortunately, i did not create an end_date..so now I need to add 1 month to the queried 'start_date' if that makes sense. The purpose for what Im doing it simply to prevent confusion in saving bill copies. Currently we are calling a bill with a start_date of January...a January bill. We really need to call it a February bill. Will this still work in this situation? Edited January 12, 2015 by Butterbean Quote Link to comment https://forums.phpfreaks.com/topic/293861-how-to-echo-a-date-value-as-date-1-month/#findComment-1502628 Share on other sites More sharing options...
Butterbean Posted January 12, 2015 Author Share Posted January 12, 2015 Based on what I see, I tried this... no luck. $query = sqlsrv_query($conn, $sql);if ($query === false){ exit("<pre>".print_r(sqlsrv_errors(), true));}while ($row = sqlsrv_fetch_array($query)){ echo "<tr> <td><a href='view_invoice.php?meter_id=$meter_id&subaccount=$subaccount&start_date=$row[start_date]'>$row[meter_id]</a></td> <td>" . date("F Y",strtotime($row['start_date'])) . "+1 month") . "</td><td>$row[invoice_no]</td><td>" . date_format($row['invoice_date'],'Y-m-d') . "</td><td><a href='approve_payment.php?meter_id=$meter_id&subaccount=$subaccount&start_date=$row[start_date]'>Pay Invoice</a></td> </tr>";}sqlsrv_free_stmt($query); ?> $query = sqlsrv_query($conn, $sql);if ($query === false){ exit("<pre>".print_r(sqlsrv_errors(), true));}while ($row = sqlsrv_fetch_array($query)){ echo "<tr> <td><a href='view_invoice.php?meter_id=$meter_id&subaccount=$subaccount&start_date=$row[start_date]'>$row[meter_id]</a></td> <td>" . date("F Y",strtotime($row['start_date'])) . "+1 month") "</td><td>$row[invoice_no]</td><td>" . date_format($row['invoice_date'],'Y-m-d') . "</td><td><a href='approve_payment.php?meter_id=$meter_id&subaccount=$subaccount&start_date=$row[start_date]'>Pay Invoice</a></td> </tr>";}sqlsrv_free_stmt($query); ?> Quote Link to comment https://forums.phpfreaks.com/topic/293861-how-to-echo-a-date-value-as-date-1-month/#findComment-1502629 Share on other sites More sharing options...
Solution wezhind Posted January 12, 2015 Solution Share Posted January 12, 2015 (edited) Use the method I supplied to create the correct date+1mnth (the first 2 steps) and then just include the variable you've created in your output. Let me know if that works. edit: like this $query = sqlsrv_query($conn, $sql);if ($query === false){ exit("<pre>".print_r(sqlsrv_errors(), true));} while ($row = sqlsrv_fetch_array($query)){ $thedatetouse = $row['start_date']; $dateplusamonth = strtotime(date("Y-m-d", strtotime($thedatetouse)) . "+1 month"); echo "<tr> <td><a href='view_invoice.php?meter_id=$meter_id&subaccount=$subaccount&start_date=$row[start_date]'>$row[meter_id]</a> </td> <td>" . date("F Y", $dateplusamonth) . "</td><td>$row[invoice_no]</td> <td>" . date_format($row['invoice_date'],'Y-m-d') . "</td> <td><a href='approve_payment.php?meter_id=$meter_id&subaccount=$subaccount&start_date=$row[start_date]'>Pay Invoice</a></td> </tr>";} sqlsrv_free_stmt($query); ?> http://php.net/manua...nction.date.php http://php.net/manua...n.strtotime.php Edited January 12, 2015 by wezhind Quote Link to comment https://forums.phpfreaks.com/topic/293861-how-to-echo-a-date-value-as-date-1-month/#findComment-1502631 Share on other sites More sharing options...
Butterbean Posted January 12, 2015 Author Share Posted January 12, 2015 Worked like a charm thank you. Quote Link to comment https://forums.phpfreaks.com/topic/293861-how-to-echo-a-date-value-as-date-1-month/#findComment-1502635 Share on other sites More sharing options...
Barand Posted January 12, 2015 Share Posted January 12, 2015 (edited) CAUTION when add time periods to dates at the end of the month $dateToUse = '2015-01-31'; $plus1month = date('Y-m-d', strtotime("$dateToUse +1 months")); echo $plus1month; //--> 2015-03-03 !!! [edit] I don't know how sqlserver handles it but MySQL gives a more natural result mysql> SELECT '2015-01-30' + INTERVAL 1 MONTH; +---------------------------------+ | '2015-01-31' + INTERVAL 1 MONTH | +---------------------------------+ | 2015-02-28 | +---------------------------------+ Edited January 12, 2015 by Barand 1 Quote Link to comment https://forums.phpfreaks.com/topic/293861-how-to-echo-a-date-value-as-date-1-month/#findComment-1502677 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.