Jump to content

Check Date Between Two Dates


vinoindiamca

Recommended Posts

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

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" );

?>

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.