Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get previous year using PHP

Tags:

php

How am I able to get the value of the previous year using PHP. Are there any predefined functions for it?

like image 646
Fero Avatar asked May 05 '11 10:05

Fero


People also ask

How to get previous years in php?

you can give a value of the input tag as : <? php echo date("Y-m-d",strtotime("-1 year"));?>

How to get previous date from given date in php?

php $date = isset($_GET['date']) ? $_GET['date'] : date('Y-m-d'); $prev_date = date('Y-m-d', strtotime($date . ' -1 day')); echo $prev_date; ?>

How do I get this year start and end in php?

$year = date('Y') - 1; // Get current year and subtract 1 $start = mktime(0, 0, 0, 1, 1, $year); $end = mktime(0, 0, 0, 12, 31, $year);


2 Answers

try

echo date("Y",strtotime("-1 year")); 
like image 66
diEcho Avatar answered Sep 17 '22 15:09

diEcho


$year = date("Y"); $previousyear = $year -1; 

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

like image 44
David Stutz Avatar answered Sep 20 '22 15:09

David Stutz