-1

I'm looking to do some basic PHP to test if a variable contains the current year.

What would be my conditional statement be for this?

My $date variable has the formatting like 25 June 2016.

And could I do a similar conditional statement for the year after?

michaelmcgurk
  • 6,367
  • 23
  • 94
  • 190
  • 1
    http://php.net/date http://php.net/strpos – Marc B Aug 04 '16 at 16:39
  • $dates = get_field('listing_date'); $findme = '2016'; $pos = strpos($dates, $findme); if ($pos === false) { $showhide = 'style="display:none"'; } else { $showhide = 'style="display:block"'; } – michaelmcgurk Aug 04 '16 at 18:16

1 Answers1

1

PHP has a class DateTime you can use.

$date = DateTime::createFromFormat('j F Y', '25 June 2016');
echo $date->format('Y');
Mojtaba
  • 4,852
  • 5
  • 21
  • 38