Piwik\Date::subDay PHP Method

subDay() public method

Subtracts $n number of days from $this date and returns a new Date object.
public subDay ( integer $n ) : Date
$n integer An integer > 0.
return Date
    public function subDay($n)
    {
        if ($n === 0) {
            return clone $this;
        }
        $ts = strtotime("-{$n} day", $this->timestamp);
        return new Date($ts, $this->timezone);
    }

Usage Example

Esempio n. 1
0
 /**
  * Updates the field ts_created for the specified websites.
  *
  * @param $idSites int Id Site to update ts_created
  * @param $minDate Date to set as creation date. To play it safe it will substract one more day.
  *
  * @ignore
  */
 public function updateSiteCreatedTime($idSites, Date $minDate)
 {
     $idSites = Site::getIdSitesFromIdSitesString($idSites);
     Piwik::checkUserHasAdminAccess($idSites);
     // Update piwik_site.ts_created
     $query = "UPDATE " . Common::prefixTable("site") . " SET ts_created = ?" . " WHERE idsite IN ( " . implode(",", $idSites) . " )\n\t\t\t\t\tAND ts_created > ?";
     $minDateSql = $minDate->subDay(1)->getDatetime();
     $bind = array($minDateSql, $minDateSql);
     Db::query($query, $bind);
 }
All Usage Examples Of Piwik\Date::subDay