Apologies for the exceptionally vague title, I'm not sure of the exact terminology to use here.
I've written some PHP to store a variable for the current year and then another variable to store the current year minus 4 (four years ago). As a note I do want it to be the whole year, hence appending 1 Jan.
// Get current date
$date = date_create('now');
// Store two digit version of current year
$yearnow = date_format($date, 'y') . "-01-01";
// Reduce the year count by two
$yearminusfour = $yearnow - 4 . "-01-01";
No problems there, although maybe there's a more efficient way to do this. However, I'm then using this to dynamically grab posts from the last four years in WordPress.
This line of code that's responsible for returning the right posts works fine when static:
$where .= " AND post_date >= '2010-01-01' AND post_date < '2014-01-01'";
What I'm struggling with is combining the two to make it dynamic. I've tried:
$where .= " AND post_date >= $yearnow AND post_date < $yearminusfour";
$where .= " AND post_date >= '.$yearnow.' AND post_date < '.$yearminusfour.'";
$where .= " AND post_date >= '".$twentyten."' AND post_date < '".$yearminusfour."'";
I'm stuck and I'm sure I'm being slow.