0

I feel like an idiot and I'm probably missing something obvious. I created a function which, for simplicity I've reduced to:

function displayDate(){
   echo date("M j, Y g:ia", $startDate);
} 

I also have the following code:

echo date("M j, Y g:ia", $startDate);

These are both outputting different things. The first one is Dec 31, 1969 5:00pm, the second one is Nov 8, 2017 7:30pm.

Why is this happening? They're getting their information from the same place. These 2 pieces of code are right next to each other.

EDIT: for more info, I'm using Processwire CMS and the $startDate is being taken from a datetime field type.

Aly Q
  • 71
  • 1
  • 9
  • 4
    variable scope issue –  Nov 07 '17 at 21:40
  • Just to explain what @nogad said, you need to inject the `$startDate` as an argument of your function like this `function displayDate($startDate)` and then include it in the call to that function. Currently it's undefined and you probably get a warning for it. – ArtisticPhoenix Nov 07 '17 at 23:25

0 Answers0