Add xx month or xx day to a date

To add xx day or xx month to a date using this method.

1
2
3
4
5
6
7
8
9
10
11
12
$mktime = explode("-",$rs_loan['datestart']);
 
$x = 5;
 
//to add $x to day
$newdate = date("Y-m-d",mktime(0,0,0,$mktime[1],$mktime[2]+$x,$mktime[0]));
 
//to add $x to month
$newdate = date("Y-m-d",mktime(0,0,0,$mktime[1]+$x,$mktime[2],$mktime[0]));
 
//to add $x to year
$newdate = date("Y-m-d",mktime(0,0,0,$mktime[1],$mktime[2],$mktime[0]+$x));

One thought on “Add xx month or xx day to a date

  1. Pingback: PHP date function | blog.azwan.net

Leave a Reply

Your email address will not be published. Required fields are marked *