Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a date after 15 days/1 month in PHP?

Tags:

In my PHP code I have a date in my variable "$postedDate".
Now I want to get the date after 7 days, 15 days, one month and 2 months have elapsed.

Which date function should I use?

Output date format should be in US format.

like image 471
Shyju Avatar asked May 06 '09 06:05

Shyju


People also ask

How can I get last 15 days in PHP?

PHP date_sub() Function$date=date_create("2013-03-15");

How can I calculate date after 10 days in PHP?

echo date("Y-m-d", strtotime("+10 days", strtotime($start_date))); You try like above. Replace from "+10 days" to your desired value to get the number of days added as you wish.

How can I get 30 days from date in PHP?

php $next_due_date = date('05/06/2016', strtotime("+30 days")); echo $next_due_date; ?>

How can I get the date of a specific day with PHP?

You can use the date function. I'm using strtotime to get the timestamp to that day ; there are other solutions, like mktime , for instance.


2 Answers

Use strtotime.

$newDate = strtotime('+15 days',$date) 

$newDate will now be 15 days after $date. $date is unix time.

http://uk.php.net/strtotime

like image 71
PaulJWilliams Avatar answered Sep 21 '22 18:09

PaulJWilliams


try this

$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 40
Sadegh Avatar answered Sep 23 '22 18:09

Sadegh