Menu

## Units

Units.php : 34

Trait Units.

Add, subtract and set units.

### Table of Contents

#### Methods

add() : static
  Add given units or interval to the current instance.
addRealUnit() : static
addUnit() : static
  Add given units to the current instance.
addUTCUnit() : static
  Add seconds to the instance using timestamp. Positive $value travels forward while negative $value travels into the past.
isModifiableUnit() : bool
  Returns true if a property can be changed via setter.
rawAdd() : static
  Call native PHP DateTime/DateTimeImmutable add() method.
rawSub() : static
  Call native PHP DateTime/DateTimeImmutable sub() method.
sub() : static
  Subtract given units or interval to the current instance.
subRealUnit() : static
subtract() : static
  Subtract given units or interval to the current instance.
subUnit() : static
  Subtract given units to the current instance.
subUTCUnit() : static
  Subtract seconds to the instance using timestamp. Positive $value travels into the past while negative $value travels forward.
rawAddUnit() : static|null

### Methods

#### add()

Units.php : 251

Add given units or interval to the current instance.

`public add(Unit|string|DateInterval|Closure|CarbonConverterInterface $unit[, int|float $value = 1 ][, bool|null $overflow = null ]) : static`

##### Parameters

$unit : Unit|string|DateInterval|Closure|CarbonConverterInterface
$value : int|float = 1
$overflow : bool|null = null

##### Tags

example

  $date->add('hour', 3)

example

  $date->add(15, 'days')

example

  $date->add(CarbonInterval::days(4))

##### Return values

static

#### addRealUnit()

Units.php : 47
`public addRealUnit(string $unit[, int|float|null $value = 1 ]) : static`

##### Parameters

$unit : string
$value : int|float|null = 1

##### Tags

deprecated

  Prefer to use add addUTCUnit() which more accurately defines what it's doing.

  Add seconds to the instance using timestamp. Positive $value travels forward while negative $value travels into the past.

##### Return values

static

#### addUnit()

Units.php : 289

Add given units to the current instance.

`public addUnit(Unit|string $unit[, mixed $value = 1 ][, bool|null $overflow = null ]) : static`

##### Parameters

$unit : Unit|string
$value : mixed = 1
$overflow : bool|null = null

##### Return values

static

#### addUTCUnit()

Units.php : 61

Add seconds to the instance using timestamp. Positive $value travels forward while negative $value travels into the past.

`public addUTCUnit(string $unit[, int|float|null $value = 1 ]) : static`

##### Parameters

$unit : string
$value : int|float|null = 1

##### Return values

static

#### isModifiableUnit()

Units.php : 206

Returns true if a property can be changed via setter.

`public static isModifiableUnit(string $unit) : bool`

##### Parameters

$unit : string

##### Return values

bool

#### rawAdd()

Units.php : 233

Call native PHP DateTime/DateTimeImmutable add() method.

`public rawAdd(DateInterval $interval) : static`

##### Parameters

$interval : DateInterval

##### Return values

static

#### rawSub()

Units.php : 385

Call native PHP DateTime/DateTimeImmutable sub() method.

`public rawSub(DateInterval $interval) : static`

##### Parameters

$interval : DateInterval

##### Return values

static

#### sub()

Units.php : 403

Subtract given units or interval to the current instance.

`public sub(Unit|string|DateInterval|Closure|CarbonConverterInterface $unit[, int|float $value = 1 ][, bool|null $overflow = null ]) : static`

##### Parameters

$unit : Unit|string|DateInterval|Closure|CarbonConverterInterface
$value : int|float = 1
$overflow : bool|null = null

##### Tags

example

  $date->sub('hour', 3)

example

  $date->sub(15, 'days')

example

  $date->sub(CarbonInterval::days(4))

##### Return values

static

#### subRealUnit()

Units.php : 180
`public subRealUnit(string $unit[, int $value = 1 ]) : static`

##### Parameters

$unit : string
$value : int = 1

##### Tags

deprecated

  Prefer to use add subUTCUnit() which more accurately defines what it's doing.

  Subtract seconds to the instance using timestamp. Positive $value travels into the past while negative $value travels forward.

##### Return values

static

#### subtract()

Units.php : 446

Subtract given units or interval to the current instance.

`public subtract(string|DateInterval $unit[, int|float $value = 1 ][, bool|null $overflow = null ]) : static`

##### Parameters

$unit : string|DateInterval
$value : int|float = 1
$overflow : bool|null = null

##### Tags

see
  sub()

##### Return values

static

#### subUnit()

Units.php : 377

Subtract given units to the current instance.

`public subUnit(Unit|string $unit[, mixed $value = 1 ][, bool|null $overflow = null ]) : static`

##### Parameters

$unit : Unit|string
$value : mixed = 1
$overflow : bool|null = null

##### Return values

static

#### subUTCUnit()

Units.php : 194

Subtract seconds to the instance using timestamp. Positive $value travels into the past while negative $value travels forward.

`public subUTCUnit(string $unit[, int $value = 1 ]) : static`

##### Parameters

$unit : string
$value : int = 1

##### Return values

static

#### rawAddUnit()

Units.php : 455
`private static rawAddUnit(self $date, string $unit, int|float $value) : static|null`

##### Parameters

$date : self
$unit : string
$value : int|float

##### Return values

static|null

## Search results