-1

I am having an incredibly hard time understanding strtotime even after reading the never ending questions on stack overflow on the subject....

date('Y-m-d',strtotime("+3 months",date('Y-m-d')))

Why does that not return 2013-10-09 (given today's date is 2013-07-09)

Instead it returns 1970-03-31 3 months after the PHP default date.

Hydra IO
  • 1,537
  • 1
  • 13
  • 28
  • 1
    http://php.net/manual/en/function.time.php -- Date is for formatting a timestamp. If you want to get the current timestamp, use `time()`. – Ariane Jul 10 '13 at 03:33

1 Answers1

3

Because the strtotime() expects the second argument to be numeric:

date('Y-m-d',strtotime("+3 months", time()))

or even

date('Y-m-d',strtotime("+3 months"))

PS: you could find it out yourself if used error_reporting level that includes E_NOTICE and checked your logs.

It's actually a good idea to have display_errors turned on on your development server with error_reporting at least of E_ALL. As a developer you want to be the first person to see your mistakes, don't you?

zerkms
  • 249,484
  • 69
  • 436
  • 539