• 4
Votes
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 190

Backtrace:

File: /var/www/stackquestions.com/public_html/application/views/question.php
Line: 190
Function: _error_handler

File: /var/www/stackquestions.com/public_html/application/controllers/Questions.php
Line: 416
Function: view

File: /var/www/stackquestions.com/public_html/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

How to use PHP to get the current year?

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 out-of-date. How would I make the year update automatically with PHP 4 and PHP 5?

Get full Year used:

 <?php 
    echo $curr_year = date('Y'); // it will display full year ex. 2017
?>

Or get only two digit of year used like this:

 <?php 
    echo $curr_year = date('y'); // it will display short 2 digit year ex. 17
?>
  • 1
Reply Report

My way to show the copyright, That keeps on updating automatically

Copyright © <?php $copyYear = 2017; // Set your website start date $curYear = date('Y'); // Keeps the second year updated echo $copyYear . (($copyYear != $curYear) ? '-' . $curYear : ''); ?>

It will output the results as

copyright @ 2017   //if $copyYear is 2017 
copyright @ 2017-201x    //if $copyYear is not equal to Current Year.
  • 1
Reply Report