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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...