Reputation: 25
there is one scenario. assume that:
financial year = 01/04/2017 to 31/03/2018
I have one input field
with datepicker
and date
column in database.
If any user will select today's date e.g 08/06/2017
then there should display data for this current year i.e from
01/04/2017 to 08/06/2017
with the help of date table
previous year's data i.e from
01/04/2016 to 31/03/2017
$currentdate = date('d/m/Y')
to display
whole data from db till current date.$A1 = mysqli_query($conn,'SELECT sum(netvalue) FROM
fintranWHERE
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
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
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