| Viewed 104 times

How to get current year in php


How to get current year in php

PHP
1 Answer
Mohammad Qandeel
Answered
9

using date() function 

This function takes the current timeStamp and returns it in an understandable format

Get today's date 

<?php echo date("Y-m-d"); ?>

Output based on your date 

 2019-08-16

date() function format character

  • Y - capital letters Represents a year (in four digits)
  • M - capital letters Represents short textual month (in three letters)
  • D - capital letters Represents short textual day (in three letters)
  • y -  small letters Represents a year (in two digits)
  • m - small letters Represents a month (01 to 12)
  • d -  small letters Represents the day of the month (01 to 31)

 

update copyright year automatically 

if you want to put a copyright notice in the footer of a web site and to update year automatically 

Example 

<p>&copy; 2017-<?php echo date("Y"); ?>Qandeel Academy  All Rights Reserved</p>