Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add one week to Date()

Tags:

php

How do I add 1 week to a date function with separate date variables. The date needs to be separate so I can insert it into another form. If I cant do it as separate variables can i separate them afterwards?

So:

$year = date("Y");
$month = date("m");
$day = date("d");
echo 'Current Date' . $year . '.' . $month . '.' . $day;
echo 'Date 1 Week in the Future';
like image 744
John Ayers Avatar asked Mar 03 '12 23:03

John Ayers


1 Answers

Use strtotime:

echo "Date 1 Week in the Future " . date('Y.m.d', strtotime('+1 Week'));
// Outputs: Date 1 Week in the Future 2012.03.10

To break up into separate variables (as per your comment):

$oneWeekLater = strtotime('+1 Week');

$year = date('Y', $oneWeekLater);
$month = date('m', $oneWeekLater);
$day = date('d', $oneWeekLater);

echo 'Date 1 Week in the Future' . $year . '.' . $month . '.' . $day;
like image 165
Josh Avatar answered Oct 10 '22 05:10

Josh