Db::subtractTime
Usage
string Db::subtractTime(string $period, int $length, string $from_date, [ bool $return_datestamp = true ])Description
Subtract a time period and interval from another time.Parameters
Parameter | Required | Type | Description |
---|---|---|---|
$period | Yes | string | The period of time to subtract. Supported values are: second, minute, hour, day, week, month, quarter, year |
$length | Yes | int | The number of the time period to subtract. |
$from_date | Yes | string | The date to start form, formatted as YYYY-MM-DD HH:II:SS |
$return_datestamp | No | bool | Whether or not to return a full SQL timestamp formatted in YYYY-MM-DD HH:II:SS. Otherwise, if false will return the number of seconds from the epoch. |
Return Value
Either a full SQL timestamp of the newly generated date in YYYY-MM-DD HH:II:SS format, or if $return_timestamp is false will be the number of seconds since the epoch.Examples
Subtract Time
// Subtract 90 mins from current time
$current_time = date('Y-m-d H:i:s');
$new_time = $this->db->subtractTime('minute', 90, $current_time);
echo "New time is: $new_time\n";