I'm trying to compare a date, I have two given dates, and I want to know if current date is between these given dates.
here my function
private function isDateDiscount($start, $end)
{
$start = new Zend_Date($start);
$end = new Zend_Date($end);
$today = new Zend_Date();
if ($today->isLater($start) && $today->isEarlier($end)){
return true;
} else {
return false;
}
}
I use this function in my Zend_Db_Table_Row_Abstract extension in this way:
public function getPrice($withDiscount=false)
{
$price = $this->prezzo;
if (true == $this->isDiscounted() && true == $withDiscount && $this->isDateDiscount($this->inizioSconto, $this->fineSconto)) {
$discount = $this->sconto;
$discounted = ($price*$discount)/100;
$price = round($price - $discounted, 2);
}
return $price;
}
private function isDiscounted()
{
return 0 == $this->sconto ? false : true;
}
where the value $this->inizioSconto
and $this->fineSconto
are in my Database and they are a sql Date