PHP- Adding and Subtracting days, months or years from date

8 minutes read
This post is about How to add and subtract dates from one another.
For example, this simple code can calculate what the date will be 5 weeks before or after from any specific date like: 2016-01-06 (yyyy-mm-dd).
Subtracting days from a date

The following example will subtract 2 days from 2016-01-06.

Subtracting Weeks from a date

The following example will subtract 2 weeks from 2016-01-06.

Subtracting Months from a date

The following example will subtract 2 months from 2016-01-06.

Subtracting Years from a date

The following example will subtract 2 years from 2016-01-06.

Subtracting Years from a date

The following example will subtract 5 years,5 months,5 days from 2016-01-06.

 

Facebook Twitter LinkedIn Telegram Whatsapp

Related Posts:

What is PHP ? PHP stands for Hypertext Preprocessor and is a server-side language. PHP allows web developers to create dynamic content that interacts with databases. PHP is relatively new (compared to languages such as Perl (CGI) and Java) but is quickly becom...
Some times we need the visitor’s IP address for validation, security, spam prevention etc. Getting the Visitor’s IP address is very easy in PHP. We can get the Internet Protocol (IP) address of any visitor by using PHP. Get Clients IP address using PHP script ...
How to upload a file from one server to another server using PHP cURL POST method. How to send files using PHP and cURL The cURL functions in PHP can be used to make HTTP requests to remote servers. The curl_setopt  method allows us a wide range of options to ...