1

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?

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
MatrixNinja
  • 127
  • 2
  • 2
  • 9
  • 1
    Use an if statement to check the year. if it's 2013, don't display the dash and second year. It's that simple. – John Conde Aug 08 '13 at 22:34
  • 1
    Keep in mind that copyright notices do not have much of a legal meaning. Even if you automatically update your notice, the date of publication for your content would still be the date that you actually posted the content online. – Asahiko Aug 12 '13 at 19:28

7 Answers7

7

It should be

<i>Example.com</i> &copy; 2013 <?php (date('Y') !== "2013") echo "- " . date('Y')); ?>
SunnyRed
  • 3,525
  • 4
  • 36
  • 57
6opko
  • 1,718
  • 2
  • 20
  • 28
3
$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)

orkoden
  • 18,946
  • 4
  • 59
  • 50
Chris Brown
  • 4,445
  • 3
  • 28
  • 36
2

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'] ;?>
1
<i>Example.com</i> &copy; 2013 <?=(date('Y')>2013?' - '.date('Y'):'')?>
trijin
  • 483
  • 3
  • 6
1
<?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
<i>Example.com</i> &copy; <?php echo (date('Y')==2018)?(date('Y')):'2018 - '.date('Y'); ?>
Sanjoy Kanrar
  • 899
  • 8
  • 11
0
<i>Example.com</i> &copy; <?php if (date('Y') != '2013') { echo '2013 - ' } echo date('Y'); ?>
Tobias
  • 43
  • 1
  • 8
  • 5
    could you append your answer with some commentary so that we could better understand your code? – Simas Joneliunas Jun 30 '21 at 02:09
  • While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. – Al Foиce ѫ Jun 30 '21 at 08:29