<p>I want to put a copyright notice in the footer of a web site, but I think it's incredibly tacky for the year to be outdated.</p>
<p>How would I make the year update automatically with <a href="http://en.wikipedia.org/wiki/PHP#History" rel="noreferrer">PHP 4</a> or <a href="http://en.wikipedia.org/wiki/PHP#History" rel="noreferrer">PHP 5</a>?</p>

[{'answer_id': 64009, 'author': 'Daniel Papasian', 'author_id': 7548, 'author_profile': 'https://Stackoverflow.com/users/7548', 'pm_score': 9, 'selected': False, 'text': '<pre><code>&lt;?php echo date("Y"); ?&gt;\n</code></pre>\n'}, {'answer_id': 64011, 'author': 'Mark Biek', 'author_id': 305, 'author_profile': 'https://Stackoverflow.com/users/305', 'pm_score': 5, 'selected': False, 'text': '<pre><code>strftime("%Y");\n</code></pre>\n\n<p>I love <a href="http://us3.php.net/manual/en/function.strftime.php" rel="noreferrer">strftime</a>.  It\'s a great function for grabbing/recombining chunks of dates/times. </p>\n\n<p>Plus it respects locale settings which the date function doesn\'t do.</p>\n'}, {'answer_id': 64016, 'author': 'chrisb', 'author_id': 8262, 'author_profile': 'https://Stackoverflow.com/users/8262', 'pm_score': 5, 'selected': False, 'text': '<p><a href="http://us2.php.net/date" rel="noreferrer">http://us2.php.net/date</a></p>\n\n<pre><code>echo date(\'Y\');\n</code></pre>\n'}, {'answer_id': 64027, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<pre><code>print date(\'Y\');\n</code></pre>\n\n<p>For more information, check date() function documentation: <a href="https://secure.php.net/manual/en/function.date.php" rel="noreferrer">https://secure.php.net/manual/en/function.date.php</a></p>\n'}, {'answer_id': 64087, 'author': 'Alexey Lebedev', 'author_id': 8338, 'author_profile': 'https://Stackoverflow.com/users/8338', 'pm_score': 4, 'selected': False, 'text': "<p>This one gives you the local time:</p>\n\n<pre><code>$year = date('Y'); // 2008\n</code></pre>\n\n<p>And this one <strong>UTC</strong>:</p>\n\n<pre><code>$year = gmdate('Y'); // 2008\n</code></pre>\n"}, {'answer_id': 64097, 'author': 'Erik van Brakel', 'author_id': 909, 'author_profile': 'https://Stackoverflow.com/users/909', 'pm_score': 11, 'selected': True, 'text': '<p>You can use either <a href="http://php.net/manual/en/function.date.php" rel="noreferrer">date</a> or <a href="http://php.net/manual/en/function.strftime.php" rel="noreferrer">strftime</a>. In this case I\'d say it doesn\'t matter as a year is a year, no matter what (unless there\'s a locale that formats the year differently?)</p>\n\n<p>For example:</p>\n\n<pre><code>&lt;?php echo date("Y"); ?&gt;\n</code></pre>\n\n<p>On a side note, when formatting dates in PHP it matters when you want to format your date in a different locale than your default. If so, you have to use setlocale and strftime. According to the <a href="http://php.net/manual/en/function.date.php" rel="noreferrer">php manual</a> on date:</p>\n\n<blockquote>\n  <p>To format dates in other languages,\n  you should use the setlocale() and\n  strftime()  functions instead of\n  date().</p>\n</blockquote>\n\n<p>From this point of view, I think it would be best to use strftime as much as possible, if you even have a remote possibility of having to localize your application. If that\'s not an issue, pick the one you like best.</p>\n'}, {'answer_id': 67737, 'author': 'gregmac', 'author_id': 7913, 'author_profile': 'https://Stackoverflow.com/users/7913', 'pm_score': 8, 'selected': False, 'text': "<p>My super lazy version of showing a copyright line, that automatically stays updated:</p>\n\n<pre><code>&amp;copy; &lt;?php \n$copyYear = 2008; \n$curYear = date('Y'); \necho $copyYear . (($copyYear != $curYear) ? '-' . $curYear : '');\n?&gt; Me, Inc.\n</code></pre>\n\n<p>This year (2008), it will say:</p>\n\n<blockquote>\n  <p>&copy; 2008 Me, Inc.</p>\n</blockquote>\n\n<p>Next year, it will say:</p>\n\n<blockquote>\n  <p>&copy; 2008-2009 Me, Inc.</p>\n</blockquote>\n\n<p>and forever stay updated with the current year.</p>\n\n<hr>\n\n<p>Or (PHP 5.3.0+) a compact way to do it using an anonymous function so you don't have variables leaking out and don't repeat code/constants:</p>\n\n<pre><code>&amp;copy; \n&lt;?php call_user_func(function($y){$c=date('Y');echo $y.(($y!=$c)?'-'.$c:'');}, 2008); ?&gt; \nMe, Inc.\n</code></pre>\n"}, {'answer_id': 12201484, 'author': 'PanicGrip', 'author_id': 1469934, 'author_profile': 'https://Stackoverflow.com/users/1469934', 'pm_score': 3, 'selected': False, 'text': '<p>If your server supports Short Tags, or you use PHP 5.4, you can use:</p>\n\n<pre><code>&lt;?=date("Y")?&gt;\n</code></pre>\n'}, {'answer_id': 14126896, 'author': 'Thomas Kelley', 'author_id': 266374, 'author_profile': 'https://Stackoverflow.com/users/266374', 'pm_score': 6, 'selected': False, 'text': '<p>With PHP heading in a more object-oriented direction, I\'m surprised nobody here has referenced the built-in <a href="http://php.net/manual/en/book.datetime.php" rel="noreferrer"><code>DateTime</code></a> class:</p>\n\n<pre><code>$now = new DateTime();\n$year = $now-&gt;format("Y");\n</code></pre>\n\n<p>or one-liner with class member access on instantiation (php>=5.4):</p>\n\n<pre><code>$year = (new DateTime)-&gt;format("Y");\n</code></pre>\n'}, {'answer_id': 21190124, 'author': 'Abdul Rahman A Samad', 'author_id': 2065804, 'author_profile': 'https://Stackoverflow.com/users/2065804', 'pm_score': 4, 'selected': False, 'text': '<p>Here\'s what I do: </p>\n\n<pre><code>&lt;?php echo date("d-m-Y") ?&gt;\n</code></pre>\n\n<p>below is a bit of explanation of what it does: </p>\n\n<pre><code>d = day\nm = month\nY = year\n</code></pre>\n\n<p>Y will gives you four digit (e.g. 1990) and y for two digit (e.g. 90)</p>\n'}, {'answer_id': 23005793, 'author': 'kkarayat', 'author_id': 1979400, 'author_profile': 'https://Stackoverflow.com/users/1979400', 'pm_score': 3, 'selected': False, 'text': "<p><code>echo date('Y')</code> gives you current year, and this will update automatically since <code>date()</code> give us the current date.</p>\n"}, {'answer_id': 26158785, 'author': 'Gaurav', 'author_id': 4046430, 'author_profile': 'https://Stackoverflow.com/users/4046430', 'pm_score': -1, 'selected': False, 'text': "<pre><code>&lt;?php\n$time_now=mktime(date('h')+5,date('i')+30,date('s'));\n$dateTime = date('d_m_Y   h:i:s A',$time_now);\n\necho $dateTime;\n?&gt;\n</code></pre>\n"}, {'answer_id': 26399196, 'author': 'joan16v', 'author_id': 1398876, 'author_profile': 'https://Stackoverflow.com/users/1398876', 'pm_score': 4, 'selected': False, 'text': '<p>For 4 digit representation:</p>\n\n<pre><code>&lt;?php echo date(\'Y\'); ?&gt;\n</code></pre>\n\n<p>2 digit representation:</p>\n\n<pre><code>&lt;?php echo date(\'y\'); ?&gt;\n</code></pre>\n\n<p>Check the php documentation for more info:\n<a href="https://secure.php.net/manual/en/function.date.php" rel="noreferrer">https://secure.php.net/manual/en/function.date.php</a></p>\n'}, {'answer_id': 40255730, 'author': 'saadk', 'author_id': 2078007, 'author_profile': 'https://Stackoverflow.com/users/2078007', 'pm_score': 3, 'selected': False, 'text': '<p>Just write:</p>\n\n<pre><code>date("Y") // A full numeric representation of a year, 4 digits\n          // Examples: 1999 or 2003\n</code></pre>\n\n<p>Or:</p>\n\n<pre><code>date("y"); // A two digit representation of a year     Examples: 99 or 03\n</code></pre>\n\n<p>And \'echo\' this value...</p>\n'}, {'answer_id': 40836184, 'author': 'Milan', 'author_id': 1438675, 'author_profile': 'https://Stackoverflow.com/users/1438675', 'pm_score': 3, 'selected': False, 'text': '<p>BTW... there are a few proper ways how to display site copyright. Some people have tendency to make things redundant i.e.: Copyright © have both the same meaning. The important copyright parts are:</p>\n\n<pre><code>**Symbol, Year, Author/Owner and Rights statement.** \n</code></pre>\n\n<blockquote>\n  <p>Using PHP + HTML:</p>\n</blockquote>\n\n<pre><code>&lt;p id=\'copyright\'&gt;&amp;copy; &lt;?php echo date("Y"); ?&gt; Company Name All Rights Reserved&lt;/p&gt;\n</code></pre>\n\n<p>or</p>\n\n<pre><code>&lt;p id=\'copyright\'&gt;&amp;copy; &lt;?php echo "2010-".date("Y"); ?&gt; Company Name All Rights Reserved&lt;/p\n</code></pre>\n'}, {'answer_id': 41317983, 'author': 'Ivan Barayev', 'author_id': 6293599, 'author_profile': 'https://Stackoverflow.com/users/6293599', 'pm_score': 3, 'selected': False, 'text': '<p>For up to php 5.4+</p>\n\n<pre><code>&lt;?php\n    $current= new \\DateTime();\n    $future = new \\DateTime(\'+ 1 years\');\n\n    echo $current-&gt;format(\'Y\'); \n    //For 4 digit (\'Y\') for 2 digit (\'y\')\n?&gt;\n</code></pre>\n\n<p>Or you can use it with one line</p>\n\n<pre><code>$year = (new DateTime)-&gt;format("Y");\n</code></pre>\n\n<p>If you wanna increase or decrease the year another method; add modify line like below.</p>\n\n<pre><code>&lt;?PHP \n  $now   = new DateTime;\n  $now-&gt;modify(\'-1 years\'); //or +1 or +5 years \n  echo $now-&gt;format(\'Y\');\n  //and here again For 4 digit (\'Y\') for 2 digit (\'y\')\n?&gt;\n</code></pre>\n'}, {'answer_id': 42146098, 'author': 'Wael Assaf', 'author_id': 6241797, 'author_profile': 'https://Stackoverflow.com/users/6241797', 'pm_score': 3, 'selected': False, 'text': '<p>use a PHP function which is just called <code>date()</code>.</p>\n\n<p>It takes the current date and then you provide a format to it</p>\n\n<p>and the format is just going to be Y. Capital Y is going to be a four digit year.</p>\n\n<pre><code>&lt;?php echo date("Y"); ?&gt;\n</code></pre>\n'}, {'answer_id': 42261996, 'author': 'Abdelkader Soudani', 'author_id': 720104, 'author_profile': 'https://Stackoverflow.com/users/720104', 'pm_score': 3, 'selected': False, 'text': '<pre><code>&lt;?php echo date("Y"); ?&gt;\n</code></pre>\n\n<p>This code should do</p>\n'}, {'answer_id': 46127571, 'author': 'imtaher', 'author_id': 6617609, 'author_profile': 'https://Stackoverflow.com/users/6617609', 'pm_score': 2, 'selected': False, 'text': '<pre><code>&lt;?php date_default_timezone_set("Asia/Kolkata");?&gt;&lt;?=date("Y");?&gt;\n</code></pre>\n\n<p>You can use this in footer sections to get dynamic copyright year</p>\n'}, {'answer_id': 46232016, 'author': 'Ganesh Udmale', 'author_id': 6790108, 'author_profile': 'https://Stackoverflow.com/users/6790108', 'pm_score': 3, 'selected': False, 'text': "<p>Get full Year used:</p>\n\n<pre><code> &lt;?php \n    echo $curr_year = date('Y'); // it will display full year ex. 2017\n?&gt;\n</code></pre>\n\n<p>Or get only two digit of year used like this:</p>\n\n<pre><code> &lt;?php \n    echo $curr_year = date('y'); // it will display short 2 digit year ex. 17\n?&gt;\n</code></pre>\n"}, {'answer_id': 47216489, 'author': 'Sushank Pokharel', 'author_id': 7599216, 'author_profile': 'https://Stackoverflow.com/users/7599216', 'pm_score': 2, 'selected': False, 'text': '<p>My way to show the copyright, That keeps on updating automatically</p>\n\n<pre><code>&lt;p class="text-muted credit"&gt;Copyright &amp;copy;\n    &lt;?php\n        $copyYear = 2017; // Set your website start date\n        $curYear = date(\'Y\'); // Keeps the second year updated\n        echo $copyYear . (($copyYear != $curYear) ? \'-\' . $curYear : \'\');\n    ?&gt; \n&lt;/p&gt;    \n</code></pre>\n\n<p>It will output the results as</p>\n\n<pre><code>copyright @ 2017   //if $copyYear is 2017 \ncopyright @ 2017-201x    //if $copyYear is not equal to Current Year.\n</code></pre>\n'}, {'answer_id': 53956475, 'author': 'Sanu0786', 'author_id': 10143531, 'author_profile': 'https://Stackoverflow.com/users/10143531', 'pm_score': 3, 'selected': False, 'text': '<p>use a PHP <code>date()</code> function.</p>\n\n<p>and the format is just going to be Y. Capital Y is going to be a four digit year.</p>\n\n<pre><code>&lt;?php echo date("Y"); ?&gt;\n</code></pre>\n'}, {'answer_id': 55187259, 'author': 'Omid Ahmadyani', 'author_id': 7006183, 'author_profile': 'https://Stackoverflow.com/users/7006183', 'pm_score': 2, 'selected': False, 'text': '<p>best shortcode for this section:</p>\n\n<pre><code>&lt;?= date("Y"); ?&gt;\n</code></pre>\n'}, {'answer_id': 56552509, 'author': 'andcl', 'author_id': 3099449, 'author_profile': 'https://Stackoverflow.com/users/3099449', 'pm_score': -1, 'selected': False, 'text': '<p>If you are using the <a href="https://carbon.nesbot.com/" rel="nofollow noreferrer">Carbon PHP API extension for DateTime</a>, you can achieve it easy:</p>\n\n<p><code>&lt;?php echo Carbon::now()-&gt;year; ?&gt;</code></p>\n'}, {'answer_id': 60972190, 'author': 'Hernán Eche', 'author_id': 231382, 'author_profile': 'https://Stackoverflow.com/users/231382', 'pm_score': 1, 'selected': False, 'text': '<pre><code>$year = date(&quot;Y&quot;, strtotime($yourDateVar));\n</code></pre>\n'}, {'answer_id': 64936968, 'author': 'allenski', 'author_id': 9132582, 'author_profile': 'https://Stackoverflow.com/users/9132582', 'pm_score': 1, 'selected': False, 'text': '<p>in my case the copyright notice in the footer of a wordpress web site needed updating.</p>\n<p>thought simple, but involved a step or more thann anticipated.</p>\n<ol>\n<li><p>Open <code>footer.php</code> in your theme\'s folder.</p>\n</li>\n<li><p>Locate copyright text, expected this to be all hard coded but found:</p>\n<pre class="lang-php prettyprint-override"><code>&lt;div id=&quot;copyright&quot;&gt;\n    &lt;?php the_field(\'copyright_disclaimer\', \'options\'); ?&gt;\n&lt;/div&gt;\n</code></pre>\n</li>\n<li><p>Now we know the year is written somewhere in WordPress admin so locate that to delete the year written text. In WP-Admin, go to <code>Options</code> on the left main admin menu:</p>\n<p><a href="https://i.stack.imgur.com/ZQ1CO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZQ1CO.png" alt="enter image description here" /></a> Then on next page go to the tab <code>Disclaimers</code>:</p>\n<p><a href="https://i.stack.imgur.com/DjvU2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DjvU2.png" alt="enter image description here" /></a> and near the top you will find Copyright year:</p>\n<p><a href="https://i.stack.imgur.com/vBPDR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vBPDR.png" alt="enter image description here" /></a> DELETE the © symbol + year + the empty space following the year, then save your page with <code>Update</code> button at top-right of page.</p>\n</li>\n<li><p>With text version of year now delete, we can go and add our year that updates automatically with PHP. Go back to chunk of code in <strong>STEP 2</strong> found in <code>footer.php</code> and update that to this:</p>\n<pre class="lang-php prettyprint-override"><code>&lt;div id=&quot;copyright&quot;&gt;\n    &amp;copy;&lt;?php echo date(&quot;Y&quot;); ?&gt; &lt;?php the_field(\'copyright_disclaimer\', \'options\'); ?&gt;\n&lt;/div&gt;\n</code></pre>\n</li>\n<li><p><strong>Done!</strong> Just need to test to ensure changes have taken effect as expected.</p>\n</li>\n</ol>\n<p>this might not be the same case for many, however we\'ve come across this pattern among quite a number of our client sites and thought it would be best to document here.</p>\n'}, {'answer_id': 65932045, 'author': 'Billu', 'author_id': 7186739, 'author_profile': 'https://Stackoverflow.com/users/7186739', 'pm_score': 0, 'selected': False, 'text': '<p>Print current month with M, day with D and year with Y.</p>\n<pre><code>&lt;?php echo date(&quot;M D Y&quot;); ?&gt;\n</code></pre>\n'}, {'answer_id': 65989381, 'author': 'ephantus okumu', 'author_id': 11665231, 'author_profile': 'https://Stackoverflow.com/users/11665231', 'pm_score': 3, 'selected': False, 'text': "<p>To get the current year using PHP’s date function, you can pass in the “Y” format character like so:</p>\n<pre><code>//Getting the current year using\n//PHP's date function.\n\n$year = date(&quot;Y&quot;);\necho $year;\n</code></pre>\n<p>The example above will print out the full 4-digit representation of the current year.</p>\n<p>If you only want to retrieve the 2-digit format, then you can use the lowercase “y” format character:</p>\n<pre><code>$year = date(&quot;y&quot;);\necho $year;\n1\n2\n$year = date(&quot;y&quot;);\necho $year;\n</code></pre>\n<p>The snippet above will print out 20 instead of 2020, or 19 instead of 2019, etc.</p>\n"}, {'answer_id': 66439431, 'author': 'Pascal Tovohery', 'author_id': 7751011, 'author_profile': 'https://Stackoverflow.com/users/7751011', 'pm_score': 0, 'selected': False, 'text': '<p>For more pricise in second param in date function\n<a href="https://www.php.net/manual/en/function.strtotime.php" rel="nofollow noreferrer">strtotime</a> return the timestamp passed by param</p>\n<pre><code>// This work when you get time as string\necho date(\'Y\', strtotime(&quot;now&quot;));\n\n// Get next years\necho date(\'Y\', strtotime(&quot;+1 years&quot;));\n\n// \necho strftime(&quot;%Y&quot;, strtotime(&quot;now&quot;));\n</code></pre>\n<p>With datetime class</p>\n<pre><code>echo (new DateTime)-&gt;format(\'Y\');\n</code></pre>\n'}, {'answer_id': 68000321, 'author': 'Ayaz Khalid', 'author_id': 16232615, 'author_profile': 'https://Stackoverflow.com/users/16232615', 'pm_score': 1, 'selected': False, 'text': "<p>In Laravel</p>\n<pre><code>$date = Carbon::now()-&gt;format('Y');\nreturn $date;\n</code></pre>\n<p>In PHP</p>\n<pre><code>echo date(&quot;Y&quot;);\n</code></pre>\n"}, {'answer_id': 69104109, 'author': 'Md. Saifur Rahman', 'author_id': 14350717, 'author_profile': 'https://Stackoverflow.com/users/14350717', 'pm_score': 0, 'selected': False, 'text': '<p>create a helper function and call it</p>\n<pre><code>getCurrentYear();\n\nfunction getCurrentYear(){\n    return now()-&gt;year;\n}\n</code></pre>\n'}, {'answer_id': 70568985, 'author': 'CodAIK', 'author_id': 14585422, 'author_profile': 'https://Stackoverflow.com/users/14585422', 'pm_score': 3, 'selected': False, 'text': "<pre><code>$dateYear = date('Y');\necho &quot;Current Year: $dateYear&quot;;\n</code></pre>\n<blockquote>\n<p>Current Year: 2022</p>\n</blockquote>\n<pre><code>$dateYear = date('y');\necho $dateYear;\n</code></pre>\n<blockquote>\n<p>22</p>\n</blockquote>\n"}]
['https://Stackoverflow.com/questions/64003', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1661459/']