Db::addTime
Usage
string Db::addTime(string $period, int $length, [ string $from_date = '' ], [ bool $return_datestamp = true ])Description
Add a time period and interval to another time.Parameters
Parameter | Required | Type | Description |
---|---|---|---|
$period | Yes | string | The period of time to add. Supported values are: second, minute, hour, day, week, month, quarter, year |
$length | Yes | int | The number of the period to add. |
$from_date | No | string | The date to add time to. Defaults to the current time. |
$return_datestamp | No | bool | Whether or not to return a timestamp in YYYY-MM-DD HH:II:SS format, or if false will return the number of seconds since the epoch. Defaults to true. |
Return Value
Either the SQL timestamp formatted in YYYY-MM-DD HH:II:SS or the number of seconds since the epoch of the newly created date.Examples
Add 30 Minutes
$new_date = $this->db->addTime('minute', 30);
echo "New date is $new_date\n";
Add 3 Days From Existing Timestamp
$start_date = '2022-03-17 12:00:00';
$new_date = $this->db->addTime('day', 3, $start_date);
echo "New date is $new_date\n";