Tejpal Posted May 7, 2016 Share Posted May 7, 2016 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 Link to comment Share on other sites More sharing options...
justsomeguy Posted May 9, 2016 Share Posted May 9, 2016 What happens when you run that code? Link to comment Share on other sites More sharing options...
Tejpal Posted May 11, 2016 Author Share Posted May 11, 2016 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 Link to comment Share on other sites More sharing options...
justsomeguy Posted May 11, 2016 Share Posted May 11, 2016 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? Link to comment Share on other sites More sharing options...
Tejpal Posted May 11, 2016 Author Share Posted May 11, 2016 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 Link to comment Share on other sites More sharing options...
justsomeguy Posted May 11, 2016 Share Posted May 11, 2016 Why do you think that's the problem? Print out the SQL query to see what you're sending to MySQL. 1 Link to comment Share on other sites More sharing options...
Tejpal Posted May 25, 2016 Author Share Posted May 25, 2016 (edited) 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 May 25, 2016 by Tejpal Link to comment Share on other sites More sharing options...
Arvind Kumar Shukla Posted August 5, 2020 Share Posted August 5, 2020 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; } Link to comment Share on other sites More sharing options...
Funce Posted August 6, 2020 Share Posted August 6, 2020 Please do not reply to old topics. Link to comment Share on other sites More sharing options...
Recommended Posts