how do I make a php footer dynamic copyright starting this year?

18.4k Views Asked by At

Here's my copyright as of right now:

<i>Example.com</i> &copy; 2013 - <?php echo date('Y'); ?>

this is okay next year because it will read:

Example.com © 2013 - 2014

but this year it says: © 2013-2013

How can I make it © 2013 and auto switch to © 2013-2014 next year, without having to come back and change it by hand?

7

There are 7 best solutions below

1
On BEST ANSWER

It should be

<i>Example.com</i> &copy; 2013 <?php (date('Y') !== "2013") echo "- " . date('Y')); ?>
0
On
<i>Example.com</i> &copy; 2013 <?=(date('Y')>2013?' - '.date('Y'):'')?>
0
On
$startYear = 2013; 
$currentYear = date('Y');
echo $startYear;
if ($startYear != $currentYear) {
    echo '-' . $currentYear;
}

That handles the years part of the Copyright message, just enter the other formatting around the output as you require.

(I've aimed for the longer but more readable approach, take your pick)

0
On

You can use the php code to get dynamic year as well as the domain of your hosting server

<?php echo "&copy; ". date(Y)." ".$_SERVER['HTTP_HOST'] ;?>
2
On
<i>Example.com</i> &copy; <?php if (date('Y') != '2013') { echo '2013 - ' } echo date('Y'); ?>
0
On
<?php function auto_copyright($year = 'auto'){ ?>
   <?php if(intval($year) == 'auto'){ $year = date('Y'); } ?>
   <?php if(intval($year) == date('Y')){ echo intval($year); } ?>
   <?php if(intval($year) < date('Y')){ echo intval($year) . ' - ' . date('Y'); } ?>
   <?php if(intval($year) > date('Y')){ echo date('Y'); } ?>
<?php } ?>
//where you want to use just paste it:
<?php auto_copyright('2010'); ?>//2010-2015
<?php auto_copyright(); ?>//current year i.e:2015
0
On
<i>Example.com</i> &copy; <?php echo (date('Y')==2018)?(date('Y')):'2018 - '.date('Y'); ?>