Henrik Petterson
Henrik Petterson

Reputation: 7094

Hide year if it is the current year

I have a function to display the date of an article:

get_the_date('M j, Y');

This will return the date in a string:

Apr 10, 2015

I want to hide the year if it is the current year. What would be the best way to do this?

Upvotes: 1

Views: 181

Answers (2)

yaron
yaron

Reputation: 1333

$date_str=get_the_date('M j, Y');
$parts= explode(",",date_str );
// some validation
if ($parts[1]==date("Y")) //then same year
{
  $date_str = $parts[0]; //just the month
}

//your string in $date_str...

Upvotes: 2

RNK
RNK

Reputation: 5792

As we don't know what's there in your get_the_date function. This might help you.

if(date('Y')==get_the_date('Y')){
    get_the_date('M j');
}
else{
    get_the_date('M j, Y');
}

Upvotes: 1

Related Questions