Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add days to a date in PHP

Tags:

function

date

php

Is there any php function available where I can add days to a date to make up another date? For example, I have a date in the following format: 27-December-2011

If I add 7 to the above, it should give: 03-January-2012.

Many thanks

like image 656
user1038814 Avatar asked Nov 10 '11 20:11

user1038814


People also ask

How do you add 2 days to a date?

var myDate = new Date(new Date(). getTime()+(5*24*60*60*1000));

How do you add a day in Strtotime?

echo date ( 'Y-m-d' , strtotime ( $Date . ' + 10 days' )); ?> Method 2: Using date_add() Function: The date_add() function is used to add days, months, years, hours, minutes and seconds.


2 Answers

Try this

$add_days = 7;
$date = date('Y-m-d',strtotime($date) + (24*3600*$add_days));
like image 101
Fabrizio Avatar answered Sep 18 '22 04:09

Fabrizio


Look at this simple snippet

$date = date("Y-m-d");// current date

$date = strtotime(date("Y-m-d", strtotime($date)) . " +1 day");
$date = strtotime(date("Y-m-d", strtotime($date)) . " +1 week");
$date = strtotime(date("Y-m-d", strtotime($date)) . " +2 week");
$date = strtotime(date("Y-m-d", strtotime($date)) . " +1 month");
$date = strtotime(date("Y-m-d", strtotime($date)) . " +30 days");
like image 20
Simone Avatar answered Sep 21 '22 04:09

Simone