TheBlackBenzKid
TheBlackBenzKid

Reputation: 27087

PHP IF else on Time

$today=date("d");       # today
$startdate="14";        # start of advent 14th/13th
$enddate="25";          # end of advent 24th/25th
//strtomtime
?>
<!DOCTYPE HTML><html><head><meta charset="utf-8"><title>Christmas Advant Calendar</title></head><body>

<div class="adventframework">

    <?php
        /*$i=$startdate;
        while($i<=$enddate)
        {
            echo "<div class='datebox " . $i . "' id='" . $i ."'>";
            echo "Today is the " . $i . "";
            echo "</div>";
            $i++;
        }*/ 

        if ($startdate==$today){
            echo 'today and start date match';
        }

The problem is that today is 01 and yet the script echos: today and start date match when $startdate is 14 - I am supposed to use strtotime I here; where does it go?

Upvotes: 0

Views: 141

Answers (2)

Sean H Jenkins
Sean H Jenkins

Reputation: 1780

The problem is typecasting.

Try doing

if ((int)$startdate == (int)$today)

More over set $startdate like:

$startdate = 14; //instead of $startdate = "14"

Upvotes: 4

Naftali
Naftali

Reputation: 146310

Try using strcmp()

if(strcmp($startdate, $today) === 0) { //strings match
    echo 'today and start date match';
}

Demo: http://codepad.org/lN90FUSa

Upvotes: 1

Related Questions