php - Add 1 year to Date and minus 1 Day at the same time -


what best way of adding existing date 1 year , removing 1 day. if todays date 04/09/2013 have new date 03/09/2014. there issue every 4 years year got 366 days instead of 365 , of course should change month if start date 01/09/2013 end date should 31/08/2014. please help. date fields looks that. think have mktime or time ?

$renewaldate = date('d f y', strtotime($rows['coverstartdate'])); 

datetime() accounts leap years:

// php 5.2+ $dt = new datetime($rows['coverstartdate']); $dt->modify('+1 year'); $dt->modify('-1 day'); $renewaldate  = $dt->format('d f y'); 

or:

// php 5.3+ $dt = new datetime($rows['coverstartdate']); $dt->add(new dateinterval('p1y')); $dt->sub(new dateinterval('p1d')); $renewaldate  = $dt->format('d f y'); 

or:

// php 5.5+ $renewaldate = (new datetime('04/09/2013'))->add(new dateinterval('p1y'))                                            ->sub(new dateinterval('p1d'))                                            ->format('d f y'); 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -