How can I get a date after 15 days/1 month in PHP?
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.
Date
Date Aithmetic
PHP
- asked 9 years ago
- G John
5Answer
Use strtotime.
$newDate = strtotime(' 15 days',$date)
$newDate will now be 15 days after $date. $date is unix time.
- answered 8 years ago
- G John
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");
- answered 8 years ago
- G John
This is very simple; try this:
$date = "2013-06-12"; // date you want to upgade
echo $date = date("Y-m-d", strtotime($date ." 1 day") );
- answered 8 years ago
- G John
Try this code to solve :
$date=strtotime(date('Y-m-d')); // if today :2013-05-23
$newDate = date('Y-m-d',strtotime(' 15 days',$date));
echo $newDate; //after15 days :2013-06-07
$newDate = date('Y-m-d',strtotime(' 1 month',$date));
echo $newDate; // after 1 month :2013-06-23
- answered 8 years ago
- G John
Use strtotime.
$newDate = strtotime('+15 days',$date)
$newDate will now be 15 days after $date. $date is unix time.
- answered 8 years ago
- B Butts
Your Answer