vinoindiamca Posted December 25, 2008 Share Posted December 25, 2008 Hi Please give me the code i need date between two days if given date(25-jan-2008) is between 15-jan-2008 and 15-Mar-2008 then price =2000 if given date(25-Mar-2008) is between 16-Mar-2008 to 15-Jun-2008 then price =4000 Please give me code in php to check Quote Link to comment Share on other sites More sharing options...
Mikedean Posted December 25, 2008 Share Posted December 25, 2008 This should do the trick. <?php function dateBetween( $checkDate ) { $firstDate1 = strtotime( "15-Jan-2008" ); $firstDate2 = strtotime( "15-Mar-2008" ); $secondDate1 = strtotime( "16-Mar-2008" ); $secondDate2 = strtotime( "15-Jun-2008" ); $checkDate = strtotime( $checkDate ); if( $checkDate > $firstDate1 && $checkDate < $firstDate2 ) { return "2000"; } elseif( $checkDate > $secondDate1 && $checkDate < $secondDate2 ) { return "4000"; } return "0"; } echo dateBetween( "25-Sep-2008" ); ?> Quote Link to comment Share on other sites More sharing options...
BloodyMind Posted December 25, 2008 Share Posted December 25, 2008 This should do the trick. <?php function dateBetween( $checkDate ) { $firstDate1 = strtotime( "15-Jan-2008" ); $firstDate2 = strtotime( "15-Mar-2008" ); $secondDate1 = strtotime( "16-Mar-2008" ); $secondDate2 = strtotime( "15-Jun-2008" ); $checkDate = strtotime( $checkDate ); if( $checkDate > $firstDate1 && $checkDate < $firstDate2 ) { return "2000"; } elseif( $checkDate > $secondDate1 && $checkDate < $secondDate2 ) { return "4000"; } return "0"; } echo dateBetween( "25-Sep-2008" ); ?> I agree with you but you should put >= or <= operators because this way the days itself wont return anything Quote Link to comment Share on other sites More sharing options...
Mikedean Posted December 25, 2008 Share Posted December 25, 2008 Ah very true , I thought I missed something . Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.