+49 (0) 89 2154 7447
Provenexpert
★★★★★
Google
★★★★★
BrandCrock | Gateway to Digital Brand

How to add number of days to current date in PHP?

Adding days to the current date is a common requirement among the developers and can be done in many ways. We give you an easy method to do by using PHP built-in functions of strtotime() and date().

strtotime() Function:

The strtotime() PHP function parses any English textual DateTime description into a Unix timestamp seconds since January 1 1970 00:00:00 GMT. The strtotime() function will return a timestamp on success. FALSE on failure.

Compatible with PHP 4, PHP 5, PHP 7, PHP 8

Syntax:

strtotime(datetime, timestamp);

Parameters:

Parameter nameTypeMandatoryDescription
datetimeStringYesA date/time string. Valid formats are explained in Date and Time Formats.
timestampIntegerOptionalThe timestamp is used as a base for the calculation of relative dates.

date() Function:

The date() PHP function returns a string formatted according to the given date format string using the given integer timestamp or the current time. If a non-numeric value is used for timestamp, false is returned and an E_WARNING level error is emitted.

Compatible with PHP 4, PHP 5, PHP 7, PHP 8

Syntax:

date(dateformat, timestamp);

Parameters:

Parameter nameTypeMandatoryDescription
dateformatStringYesFormat accepted by DateTimeInterface::format().
timestampIntegerOptionalThe timestamp parameter is an int Unix timestamp that defaults to the current local time if the timestamp is omitted or null.
In other words, it defaults to the value of time().

How to add number of days to current date?

Find the PHP program code snippet to add days to $Date in PHP using strtotime() function. 

Add days to timestamp:

<?php // Add days to current date and display it. echo date('d.m.Y H:i:s', strtotime('+1 days')); ?>

Output:

Current date and time: 19.11.2021 14:09:18 Output: 20.11.2021 14:09:18

Add 7 days to the current date:

<?php // Add days to current date and display it echo date('d.m.Y H:i:s', strtotime('+7 days', time())); ?>

Output:

Current date and time: 19.11.2021 14:09:18 Output: 26.11.2021 14:09:18

Add 30 days to the current date:

<?php // Add days to current date and display it echo date('d.m.Y H:i:s', strtotime('+30 days', time())); ?>

Output:

Current date and time: 19.11.2021 14:09:18 Output: 19.12.2021 14:09:18

More from our latest blogs

What additional features does Shopware Enterprise Edition have

Compared to the other versions, the Shopware Enterprise Edition  is such a complex program that

Shopware Alan Bradford Jul 11, 2018

Aquacentrum Relaunch with Shopware

Brandcrock GmbH  proudly announces the relaunch of new multilingual E-Commerce website based on Shopware for aquacentrum munich.

Shopware Vaid Ali Jul 10, 2018

Shopware Setup installation and configuration cost

What is often forgotten by customers, but is always necessary, is the installation and configuration

Shopware Alan Bradford Jun 20, 2018

Shopware Certified Partner

BrandCrock GmbH has completed it’s first year as a Shopware certified partner with Shopware AG

Shopware Mustafa Ali Jun 11, 2018
1 38 39 40 41 42
Scroll to Top