Jump to content

Recommended Posts

Hello.. i have trouble with date comparison (if user send different years it gives back 0 val)

is there a way to compare date without the year? what is the trick for this situation?

here is my code, thank you...

<?
function DatesBetween($startDate, $endDate){
    // get the number of days between the two given dates.
    $days = (strtotime($endDate) - strtotime($startDate)) / 86400 + 1;
    $startMonth = date("m", strtotime($startDate));
    $startDay = date("d", strtotime($startDate));
    $startYear = date("Y", strtotime($startDate));   
    $dates;//the array of dates to be passed back
    for($i=0; $i<$days; $i++){
        $dates[$i] = date("Y-m-d", mktime(0, 0, 0, $startMonth , ($startDay+$i), $startYear));
    }
    return $dates;   
}

$dates = DatesBetween("2007-12-31","2008/01/02");

print_r ($dates);
echo "<br><br>";
$i = 0;
while ($i < (count($dates))-1) {

if  ($dates[$i] >= (date('Y')."-01-09") && $dates[$i] <= (date('Y')."-04-08")) {
	$price = 250;
} else if  ($dates[$i] >= (date('Y')."-04-09") && $dates[$i] <= (date('Y')."-04-16")) {
	$price = 300;
} else if  ($dates[$i] >= (date('Y')."-04-17") && $dates[$i] <= (date('Y')."-07-14")) {
	$price = 250;
} else if  ($dates[$i] >= (date('Y')."-07-15") && $dates[$i] <= (date('Y')."-07-31")) {
	$price = 300;
} else if  ($dates[$i] >= (date('Y')."-08-01") && $dates[$i] <= (date('Y')."-08-31")) {
	$price = 350;
} else if  ($dates[$i] >= (date('Y')."-09-01") && $dates[$i] <= (date('Y')."-09-15")) {
	$price = 300;
} else if  ($dates[$i] >= (date('Y')."-09-16") && $dates[$i] <= (date('Y')."-12-19")) {
	$price = 250;
} else if ($dates[$i] >= (date('Y')."-20-12") && $dates[$i] <= (date('Y')."-01-10")) {
	$price = 350;
}
$i++;
echo $price;
$total+=$price;
echo "<br>";
}
echo "total =", $total;
?>

Link to comment
https://forums.phpfreaks.com/topic/62821-date-comparison/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • 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.