amit sutar
amit sutar

Reputation: 25

How to set current year and previous year in variables using php?

$A1 = mysqli_query($conn,'SELECT sum(netvalue) FROMfintranWHERE groupNo = 21 AND docDate <= "'.$currentdate.'" ');

We can create some formula but i am so poor to build logic so please help me

Upvotes: 1

Views: 1024

Answers (2)

Ajay Kumar
Ajay Kumar

Reputation: 1342

You use Carbon.
Documentation :- http://carbon.nesbot.com/docs/

$date = Carbon\Carbon::createFromFormat('d/m/Y', $date);
$date->subYear(); 
echo $date->format('d/m/Y'); // Previous year

Upvotes: 1

Robson
Robson

Reputation: 823

You can use the following method for generating date one year back:

function get_year_back_date($date, $format='d/m/Y') {
    return date($format, strtotime($date . ' -1 year'));
}

$previous_year = get_year_back_date('01/04/2017');

Here you can see this code in action: http://ideone.com/eXRoYB.

Upvotes: 1

Related Questions