Menu

## Modifiers

Modifiers.php : 25

Trait Modifiers.

Returns dates relative to current date using modifier short-hand.

### Table of Contents

#### Properties

$midDayAt : int
  Midday/noon hour.

#### Methods

average() : static
  Modify the current instance to the average of a given instance (default now) and the current instance (second-precision).
change() : static
  Similar to native modify() method of DateTime but can handle more grammars.
closest() : static
  Get the closest date from the instance (second-precision).
farthest() : static
  Get the farthest date from the instance (second-precision).
firstOfMonth() : static
  Modify to the first occurrence of a given day of the week in the current month. If no dayOfWeek is provided, modify to the first day of the current month. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
firstOfQuarter() : static
  Modify to the first occurrence of a given day of the week in the current quarter. If no dayOfWeek is provided, modify to the first day of the current quarter. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
firstOfYear() : static
  Modify to the first occurrence of a given day of the week in the current year. If no dayOfWeek is provided, modify to the first day of the current year. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
getMidDayAt() : int
  get midday/noon hour
lastOfMonth() : static
  Modify to the last occurrence of a given day of the week in the current month. If no dayOfWeek is provided, modify to the last day of the current month. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
lastOfQuarter() : static
  Modify to the last occurrence of a given day of the week in the current quarter. If no dayOfWeek is provided, modify to the last day of the current quarter. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
lastOfYear() : static
  Modify to the last occurrence of a given day of the week in the current year. If no dayOfWeek is provided, modify to the last day of the current year. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
max() : static
  Get the maximum instance between a given instance (default now) and the current instance.
maximum() : static
  Get the maximum instance between a given instance (default now) and the current instance.
midDay() : static
  Modify to midday, default to self::$midDayAt
min() : static
  Get the minimum instance between a given instance (default now) and the current instance.
minimum() : static
  Get the minimum instance between a given instance (default now) and the current instance.
modify() : static
  Calls \DateTime::modify if mutable or \DateTimeImmutable::modify else.
next() : static
  Modify to the next occurrence of a given modifier such as a day of the week. If no modifier is provided, modify to the next occurrence of the current day of the week. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
nextWeekday() : static
  Go forward to the next weekday.
nextWeekendDay() : static
  Go forward to the next weekend day.
nthOfMonth() : mixed
  Modify to the given occurrence of a given day of the week in the current month. If the calculated occurrence is outside the scope of the current month, then return false and no modifications are made.
nthOfQuarter() : mixed
  Modify to the given occurrence of a given day of the week in the current quarter. If the calculated occurrence is outside the scope of the current quarter, then return false and no modifications are made.
nthOfYear() : mixed
  Modify to the given occurrence of a given day of the week in the current year. If the calculated occurrence is outside the scope of the current year, then return false and no modifications are made.
previous() : static
  Modify to the previous occurrence of a given modifier such as a day of the week. If no dayOfWeek is provided, modify to the previous occurrence of the current day of the week. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
previousWeekday() : static
  Go backward to the previous weekday.
previousWeekendDay() : static
  Go backward to the previous weekend day.
setMidDayAt() : void
nextOrPreviousDay() : static
  Go forward or backward to the next week- or weekend-day.

### Properties

#### $midDayAt

Modifiers.php : 32

Midday/noon hour.

`protected static int $midDayAt = 12`

### Methods

#### average()

Modifiers.php : 345

Modify the current instance to the average of a given instance (default now) and the current instance (second-precision).

`public average([Carbon|DateTimeInterface|null $date = null ]) : static`

##### Parameters

$date : Carbon|DateTimeInterface|null = null

##### Return values

static

#### change()

Modifiers.php : 460

Similar to native modify() method of DateTime but can handle more grammars.

`public change(string $modifier) : static`

##### Parameters

$modifier : string

##### Tags

example

      echo Carbon::now()->change('next 2pm');

link
  https://php.net/manual/en/datetime.modify.php

##### Return values

static

#### closest()

Modifiers.php : 358

Get the closest date from the instance (second-precision).

`public closest(Carbon|DateTimeInterface|mixed $date1, Carbon|DateTimeInterface|mixed $date2) : static`

##### Parameters

$date1 : Carbon|DateTimeInterface|mixed
$date2 : Carbon|DateTimeInterface|mixed

##### Return values

static

#### farthest()

Modifiers.php : 371

Get the farthest date from the instance (second-precision).

`public farthest(Carbon|DateTimeInterface|mixed $date1, Carbon|DateTimeInterface|mixed $date2) : static`

##### Parameters

$date1 : Carbon|DateTimeInterface|mixed
$date2 : Carbon|DateTimeInterface|mixed

##### Return values

static

#### firstOfMonth()

Modifiers.php : 186

Modify to the first occurrence of a given day of the week in the current month. If no dayOfWeek is provided, modify to the first day of the current month. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.

`public firstOfMonth([int|null $dayOfWeek = null ]) : static`

##### Parameters

$dayOfWeek : int|null = null

##### Return values

static

#### firstOfQuarter()

Modifiers.php : 248

Modify to the first occurrence of a given day of the week in the current quarter. If no dayOfWeek is provided, modify to the first day of the current quarter. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.

`public firstOfQuarter([int|null $dayOfWeek = null ]) : static`

##### Parameters

$dayOfWeek : int|null = null

  day of the week default null

##### Return values

static

#### firstOfYear()

Modifiers.php : 299

Modify to the first occurrence of a given day of the week in the current year. If no dayOfWeek is provided, modify to the first day of the current year. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.

`public firstOfYear([int|null $dayOfWeek = null ]) : static`

##### Parameters

$dayOfWeek : int|null = null

  day of the week default null

##### Return values

static

#### getMidDayAt()

Modifiers.php : 39

get midday/noon hour

`public static getMidDayAt() : int`

##### Return values

int

#### lastOfMonth()

Modifiers.php : 207

Modify to the last occurrence of a given day of the week in the current month. If no dayOfWeek is provided, modify to the last day of the current month. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.

`public lastOfMonth([int|null $dayOfWeek = null ]) : static`

##### Parameters

$dayOfWeek : int|null = null

##### Return values

static

#### lastOfQuarter()

Modifiers.php : 263

Modify to the last occurrence of a given day of the week in the current quarter. If no dayOfWeek is provided, modify to the last day of the current quarter. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.

`public lastOfQuarter([int|null $dayOfWeek = null ]) : static`

##### Parameters

$dayOfWeek : int|null = null

  day of the week default null

##### Return values

static

#### lastOfYear()

Modifiers.php : 314

Modify to the last occurrence of a given day of the week in the current year. If no dayOfWeek is provided, modify to the last day of the current year. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.

`public lastOfYear([int|null $dayOfWeek = null ]) : static`

##### Parameters

$dayOfWeek : int|null = null

  day of the week default null

##### Return values

static

#### max()

Modifiers.php : 411

Get the maximum instance between a given instance (default now) and the current instance.

`public max([Carbon|DateTimeInterface|mixed $date = null ]) : static`

##### Parameters

$date : Carbon|DateTimeInterface|mixed = null

##### Return values

static

#### maximum()

Modifiers.php : 427

Get the maximum instance between a given instance (default now) and the current instance.

`public maximum([Carbon|DateTimeInterface|mixed $date = null ]) : static`

##### Parameters

$date : Carbon|DateTimeInterface|mixed = null

##### Tags

see
  max()

##### Return values

static

#### midDay()

Modifiers.php : 68

Modify to midday, default to self::$midDayAt

`public midDay() : static`

##### Return values

static

#### min()

Modifiers.php : 383

Get the minimum instance between a given instance (default now) and the current instance.

`public min([Carbon|DateTimeInterface|mixed $date = null ]) : static`

##### Parameters

$date : Carbon|DateTimeInterface|mixed = null

##### Return values

static

#### minimum()

Modifiers.php : 399

Get the minimum instance between a given instance (default now) and the current instance.

`public minimum([Carbon|DateTimeInterface|mixed $date = null ]) : static`

##### Parameters

$date : Carbon|DateTimeInterface|mixed = null

##### Tags

see
  min()

##### Return values

static

#### modify()

Modifiers.php : 439

Calls \DateTime::modify if mutable or \DateTimeImmutable::modify else.

`public modify(mixed $modify) : static`

##### Parameters

$modify : mixed

##### Tags

see
  https://php.net/manual/en/datetime.modify.php

##### Return values

static

#### next()

Modifiers.php : 83

Modify to the next occurrence of a given modifier such as a day of the week. If no modifier is provided, modify to the next occurrence of the current day of the week. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.

`public next([string|int|null $modifier = null ]) : static`

##### Parameters

$modifier : string|int|null = null

##### Return values

static

#### nextWeekday()

Modifiers.php : 120

Go forward to the next weekday.

`public nextWeekday() : static`

##### Return values

static

#### nextWeekendDay()

Modifiers.php : 140

Go forward to the next weekend day.

`public nextWeekendDay() : static`

##### Return values

static

#### nthOfMonth()

Modifiers.php : 229

Modify to the given occurrence of a given day of the week in the current month. If the calculated occurrence is outside the scope of the current month, then return false and no modifications are made.

`public nthOfMonth(int $nth, int $dayOfWeek) : mixed`

Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.

##### Parameters

$nth : int
$dayOfWeek : int

#### nthOfQuarter()

Modifiers.php : 279

Modify to the given occurrence of a given day of the week in the current quarter. If the calculated occurrence is outside the scope of the current quarter, then return false and no modifications are made.

`public nthOfQuarter(int $nth, int $dayOfWeek) : mixed`

Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.

##### Parameters

$nth : int
$dayOfWeek : int

#### nthOfYear()

Modifiers.php : 330

Modify to the given occurrence of a given day of the week in the current year. If the calculated occurrence is outside the scope of the current year, then return false and no modifications are made.

`public nthOfYear(int $nth, int $dayOfWeek) : mixed`

Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.

##### Parameters

$nth : int
$dayOfWeek : int

#### previous()

Modifiers.php : 165

Modify to the previous occurrence of a given modifier such as a day of the week. If no dayOfWeek is provided, modify to the previous occurrence of the current day of the week. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.

`public previous([string|int|null $modifier = null ]) : static`

##### Parameters

$modifier : string|int|null = null

##### Return values

static

#### previousWeekday()

Modifiers.php : 130

Go backward to the previous weekday.

`public previousWeekday() : static`

##### Return values

static

#### previousWeekendDay()

Modifiers.php : 150

Go backward to the previous weekend day.

`public previousWeekendDay() : static`

##### Return values

static

#### setMidDayAt()

Modifiers.php : 58
`public static setMidDayAt(int $hour) : void`

##### Parameters

$hour : int

  midday hour

##### Tags

deprecated

  To avoid conflict between different third-party libraries, static setters should not be used. You should rather consider mid-day is always 12pm, then if you need to test if it's an other hour, test it explicitly: $date->format('G') == 13 or to set explicitly to a given hour: $date->setTime(13, 0, 0, 0)

  Set midday/noon hour

#### nextOrPreviousDay()

Modifiers.php : 102

Go forward or backward to the next week- or weekend-day.

`private nextOrPreviousDay([bool $weekday = true ][, bool $forward = true ]) : static`

##### Parameters

$weekday : bool = true
$forward : bool = true

##### Return values

static

## Search results