Mathijs Delva
Mathijs Delva

Reputation: 211

Beginner: if else date

i'm an absolute beginner in php, and i'm just trying to make a simple if else statement. Please take a look at this:

<?php  
        $currentDate  = echo date("Y");
        $startup = '2013';
        if ($startup = $currentDate) {
      ?>
        &copy; 2013 Blue Box 22
      <?php } else { ?>
        &copy; 2013 - <?php echo date("Y"); ?> Blue Box 22
      <?php } ?>

As you can probably read, i'm just checking if the current year is equal to the startup year, and then let it display accordingly. I presume there's something wrong in my syntax as that part of my page isn't rendering.

Thank you for your help!

Upvotes: 0

Views: 162

Answers (4)

Jay
Jay

Reputation: 1

This means assigning "=" This means comparing "=="

This should help you with your code. :)

Upvotes: 0

Jakub Matczak
Jakub Matczak

Reputation: 15656

Instead of:

if ($startup = $currentDate) { 

it should be

if ($startup == $currentDate) { 

Moreover, instead of using

$currentDate  = echo date("Y");

try:

$currentDate  = date("Y");

Upvotes: 11

Susheel
Susheel

Reputation: 1679

<?php  
        $currentDate  = date("Y");//echo removed, never use while comparison
        $startup = '2013';
        if ($startup == $currentDate) {// comparison is done by ==, = make assignment
      ?>
        &copy; 2013 Blue Box 22
      <?php } else { ?>
        &copy; 2013 - <?php echo date("Y"); ?> Blue Box 22
      <?php } ?>

Upvotes: 0

Darren
Darren

Reputation: 70728

You've assigned the variable in the if statement, not compared. Comparisons are done with the == operator.

if ($startup == $currentDate) {

}

Which means if (startup is equal to the current date then do this)

Upvotes: 0

Related Questions