How to get 2 year digits in php?

I want to get the year in 2 digits, for example 15 .

using php date () function

echo date("Y"); 

but it returns all year.

any help is ambiguous. Thanks!

+5
source share
3 answers

Change uppercase "Y" to lowercase "y"

 echo date("y"); 

PHP documentation

 y A two digit representation of a year 
+30
source

http://php.net/manual/en/function.date.php

See this documentation. This is date("y") . So, lowercase y instead of Y.

+4
source

You can use the PHP substr () method to get the last two digits of the year as follows.

 $year = 2011; $year = substr( $year, -2); 

The code above gives 11 as the result, which is the last two-digit digit of 2011.

+3
source

Source: https://habr.com/ru/post/1213643/


All Articles