-5

I've currently got a cut of PHP code that shows the date a user's account was created:

$user['contract_start']

For example, if I were to make a new account today and put that on a page while the account was logged in, it would come out with

2014-07-30

How can I alter this so that the code displays a string that adds exactly 10 months to the start date?

user3670791
  • 17
  • 1
  • 4
  • 1
    -1: Where is the $user object coming from? $user['contract_start'] is of what type? Fails basic debugging steps before asking question. – FallenAvatar Jul 31 '14 at 03:46
  • possible duplicate of [Adding three months to a date in PHP](http://stackoverflow.com/questions/9875076/adding-three-months-to-a-date-in-php) – Sean Jul 31 '14 at 03:49

2 Answers2

4

try this -

date('Y-m-d', strtotime('+ 10 MONTHS', strtotime($date)))
Sougata Bose
  • 31,517
  • 8
  • 49
  • 87
  • `Warning: strtotime() expects parameter 2 to be long, string given`. Should be `date('Y-m-d', strtotime('+ 10 MONTH',strtotime($date)))`. see also http://stackoverflow.com/a/9875196/689579 – Sean Jul 31 '14 at 03:55
  • @sgt Congratulation's to 3k rep :D (Have fun to review all tasks) – Rizier123 Dec 05 '14 at 11:38
2

Using php Datetime class and Datetime::add

$user['contract_start'] = '2014-07-30';
$date = new DateTime($user['contract_start']);
$date->add(new DateInterval('P10M'));
echo $date->format('Y-m-d') . "\n";
Sean
  • 12,443
  • 3
  • 29
  • 47