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 Link to comment https://forums.phpfreaks.com/topic/138379-check-date-between-two-dates/ 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" ); ?> Link to comment https://forums.phpfreaks.com/topic/138379-check-date-between-two-dates/#findComment-723538 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 Link to comment https://forums.phpfreaks.com/topic/138379-check-date-between-two-dates/#findComment-723543 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 . Link to comment https://forums.phpfreaks.com/topic/138379-check-date-between-two-dates/#findComment-723550 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.