MrBlackDrag0nfly
MrBlackDrag0nfly

Reputation: 58

Echoing something out on a specific date every year

So I'm trying to make a message appear on one specific date of the year.

My code now:

<?php 
$year = date("Y");

if(checkdate(5, 22, $year) === TRUE) {
echo '<b>something</b>';
}else {
echo '';
}

?>

But the message appears howsoever, no matter the date.

Hope you can help me,

Thanks in advance!

Upvotes: 0

Views: 50

Answers (2)

mts7
mts7

Reputation: 583

If you don't have to use checkdate, this is an alternative.

<?php
if (date('Y-m-d') == date('Y').'-05-22') {
    echo '<b>something</b>';
}    else {
    echo '';
}
?>

Upvotes: 2

Wearwolf
Wearwolf

Reputation: 190

According to the documentation checkdate only validates dates, it doesn't compare them against the current date.

Returns TRUE if the date given is valid; otherwise returns FALSE.

Use something similar to the code you already have to check the date

if( date("n j") == "5 22")
{
    echo '<b>something</b>';
}

Upvotes: 2

Related Questions