|
Added on 06.09.09 |
| Clicks 3936 |
| Rating: 4.33 out of 5 from 6 raters |

Finding the end of the month from today's date can be very useful specially for commercial business that need to work out future payments. For example ,if you have an invoice due to be paid in 30 day from the issue but extended to the end of that month this function is just what you need .
We assume that all the functions will be saved in a file called php_functions.php
Explaining the above function is quite simple, as you can see ,it has 2
parameters,
$month is where you enter the number of month
from today, that you want to find the end,for example,if today is the 10th
of September 2009 and you enter 2 it'll output the 31st October 2009.
$format is where you put the
format you want the date to appear in your page, for complete formatting
details, visit the PHP manual page.
$today=today(8,'d-m-Y'); The variable $today will hold the actual todays date with your time zone which in this case is 8 but you can edit to correspond to your time zone.
$date=explode('-',$today) ;$date will hold the array resulting by exploding $today
$first_second_this_month = $date[2].'-'.$date[1].'-01'.' 00:00:00'; this is quite clear
$last_second_next_month = strtotime("-1 second", strtotime("+".$month." months", strtotime($first_second_this_month))); We need this to bring back the formatted date into a timestamp to calculate the end of month.
$end_of_month=date($format, $last_second_next_month); Here is where the timestamp will be formatted in a readable date with the format of your choice.
See the example below to use the function
Try the example below