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.
PHP date_sub() Function$date=date_create("2013-03-15");
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.
php $next_due_date = date('05/06/2016', strtotime("+30 days")); echo $next_due_date; ?>
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.
Use strtotime.
$newDate = strtotime('+15 days',$date)
$newDate will now be 15 days after $date. $date is unix time.
http://uk.php.net/strtotime
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");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With