Jump to content
Tejpal

financial year calculation in php

Recommended Posts

Hello everyone

I want Show Some Recorded according financial year

For Example from 01-04-2016 to 31-3-2017

01-04-2017 to 31-03-2018

my Code

 

$pst = date('Y');
$pt = date('Y', strtotime('+1 year'));

$sql="SELECT *FROM mytable where date BETWEEN CAST('$pst-04-01' AS DATE) AND CAST('$pt-03-31' AS DATE)";

 

Anyone Can explain how i done this

Share this post


Link to post
Share on other sites

not show record of jan feb march

i think when date 1 jan then my condition 1-4-17 to 31-3-18

so this not working good

Share this post


Link to post
Share on other sites

MySQL expects dates to be in yyyy-mm-dd format, so that should be fine. What about the date column in your table, what is the data type of that column?

Share this post


Link to post
Share on other sites

in mysql all ok field type date

i think prob in current year dynmic $cyear

and when date 1-1-$cyear then not show of 3 months

Share this post


Link to post
Share on other sites

Why do you think that's the problem? Print out the SQL query to see what you're sending to MySQL.

  • Like 1

Share this post


Link to post
Share on other sites
Done


<?php

$pst = date('m');


if($pst>4) {

$y=date('Y');

echo $dtt=$y."-04-01<br/>";

$pt = date('Y', strtotime('+1 year'));

echo $ptt=$pt."-03-31";

}

else {

$y=date('Y', strtotime('-1 year'));

echo $dtt=$y."-04-01<br/>";

$pt =date('Y');

echo $ptt=$pt."-03-31";

}

?>


Edited by Tejpal

Share this post


Link to post
Share on other sites

function get_finacial_year_range() {

    $year = date('Y');

    $month = date('m');

    if($month<4){

        $year = $year-1;

    }

    $start_date = date('d/m/Y',strtotime(($year).'-04-01'));

    $end_date = date('d/m/Y',strtotime(($year+1).'-03-31'));

    $response = array('start_date' => $start_date, 'end_date' => $end_date);

    return $response;

}

Share this post


Link to post
Share on other sites

Please do not reply to old topics.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×
×
  • Create New...