sitorush Posted August 1, 2007 Share Posted August 1, 2007 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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/62821-date-comparison/ 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.