PHP date() function formats a local date & time, it returns the formatted string formatted date. In this article, I described the simple process about how to add and subtract number of months from the current date using default PHP date() function.
Add number of months in current date: (Example: adding 5 months)
<?php
$limit = 5; # No.of months
$added_timestamp = strtotime('+'.$limit.' month', time());
$result = date('d.m.Y', $added_timestamp);
echo $result;
?>
Subtract number of months in current date: (Example: subtracting 5 months)
<?php
$limit = 5; # No.of months
$added_timestamp = strtotime('-'.$limit.' month', time());
$result = date('d.m.Y', $added_timestamp);
echo $result;
?>
In short form:
Add number of months in current date: (Example: adding 5 months)
<?php
echo date('d.m.Y', strtotime('+5 month', time()));
?>
Subtract number of months in current date: (Example: subtracting 5 months)
<?php
echo date('d.m.Y', strtotime('-5 month', time()));
?>

Related Posts
How to add and subtracting days using php date functionPHP date() function formats a local date and time, and returns the formatted date string. In this article, I described the simple process about how to add and subtract number of days from current date using default PHP date() function. Add number of days in current date: php strtotime add…
How to add and subtracting weeks using php date() functionPHP date() function formats a local date and time, and returns the formatted date string. In this article, I described the simple process about how to add and subtract number of weeks from current date using default PHP date() function. Add number of weeks in current date: (Example: adding 5 weeks) <?php…
How to add and subtracting years in current date using PHP date() functionPHP date() function formats a local date and time, and returns the formatted date string. In this article, I described the simple process about how to add and subtract number of years from the current date using default PHP date() function. Add number of years in current date: (Example: adding 5 years)…
-
PHP: How to copy all files from one directory to anotherI will guide you to copy all files & sub directories of the directory to another directory using PHP copy() function. There are many other functions used to copy the content of one directory to another. copy() Functionopendir() Functionis_dir() Functionscandir( ) Functionreaddir() Function PHP code for copy multiple files from…
-
PHP Fatal error: Call to undefined function imap_open() fixIf you want to work with the IMAP protocol, as well as the NNTP, POP3 and local mailbox access methods, you must install the "php-imap" package in your server. If you get the error PHP Fatal error: Call to undefined function imap_open() then php-imap package is missing in your server. Just install the missing package…
-
Generating Random String Using PHPGenerating random strings with custom specified length is most required functionality in every project. In this article, I described the easiest way to generate custom length random string. PHP program for Random String Generate: <?php /* * Function to generate random string * Default length 30 character */ function generateRandomString($length…
-
PHP: Create empty object - new stdClass,var_dumpstdClass is the default PHP object. stdClass has no properties, methods or parent. It does not support magic methods, and implements no interfaces. Standard way to create an "empty" object is: <?php $input_object = new stdClass(); var_dump($input_object); ?> Result for new stdClass(): object(stdClass)#1 (0) { } But, with PHP Version…
Converting date to epoch timestamp in Perl: str2time, strptimeUse Date::Parse to convert normal date string to epoch timestamp. Date::Parse provides two routines for parsing date strings into time values. str2time(DATE [, ZONE]) str2time parses DATE and returns a unix time value, or undef upon failure. ZONE, if given, specifies the timezone to assume when parsing if the date…
Get the last element of an array in PHP – end()The end() function is an inbuilt function in PHP Programming. The purpose of this function is to find the last element of the given input array. The end() function changes the internal pointer of an array to the last element and returns the value of the last element. end() PHP…
PHP Cheat SheetPHP code is usually processed on a web server by a PHP interpreter implemented as a module, a daemon or as a Common Gateway Interface (CGI) executable. On a web server, the result of the interpreted and executed PHP code — which may be any type of data, such as…