Difference
Trait Difference.
Depends on the following methods:
Table of Contents
Methods
- ago() : string
- Get the difference in a human readable format in the current locale from an other instance given to now
- calendar() : string
- Returns either day of week + time (e.g. "Last Friday at 3:30 PM") if reference time is within 7 days, or a calendar date (e.g. "10/29/2017") otherwise.
- copy() : void
- diff() : CarbonInterval
- diffAsCarbonInterval() : CarbonInterval
- Get the difference as a CarbonInterval instance.
- diffAsDateInterval() : DateInterval
- Get the difference as a DateInterval instance.
- diffFiltered() : int
- Get the difference by the given interval using a filter closure.
- diffForHumans() : string
- Get the difference in a human readable format in the current locale from current instance to an other instance given (or now if null given).
- diffInDays() : float
- Get the difference in days.
- diffInDaysFiltered() : int
- Get the difference in days using a filter closure.
- diffInHours() : float
- Get the difference in hours.
- diffInHoursFiltered() : int
- Get the difference in hours using a filter closure.
- diffInMicroseconds() : float
- Get the difference in microseconds.
- diffInMilliseconds() : float
- Get the difference in milliseconds.
- diffInMinutes() : float
- Get the difference in minutes.
- diffInMonths() : float
- Get the difference in months.
- diffInQuarters() : float
- Get the difference in quarters.
- diffInSeconds() : float
- Get the difference in seconds.
- diffInUnit() : float
- diffInWeekdays() : int
- Get the difference in weekdays.
- diffInWeekendDays() : int
- Get the difference in weekend days using a filter.
- diffInWeeks() : float
- Get the difference in weeks.
- diffInYears() : float
- Get the difference in years
- from() : string
- fromNow() : string
- Get the difference in a human readable format in the current locale from current instance to now.
- lessThan() : bool
- resolveCarbon() : void
- secondsSinceMidnight() : float
- The number of seconds since midnight.
- secondsUntilEndOfDay() : float
- The number of seconds until 23:59:59.
- since() : mixed
- timespan() : string
- Get the difference in a human-readable format in the current locale from current instance to another instance given (or now if null given).
- to() : string
- Get the difference in a human readable format in the current locale from an other instance given (or now if null given) to current instance.
- toNow() : string
- Get the difference in a human readable format in the current locale from an other instance given to now
- until() : string
- getIntervalDayDiff() : int
Methods
ago()
Get the difference in a human readable format in the current locale from an other instance given to now
public
ago([int|array<string|int, mixed> $syntax = null ][, bool $short = false ][, int $parts = 1 ][, int $options = null ]) : string
Parameters
- $syntax : int|array<string|int, mixed> = null
-
if array passed, parameters will be extracted from it, the array may contains:
- 'syntax' entry (see below)
- 'short' entry (see below)
- 'parts' entry (see below)
- 'options' entry (see below)
- 'join' entry determines how to join multiple parts of the string
- if $join is a string, it's used as a joiner glue
- if $join is a callable/closure, it get the list of string and should return a string- if $join is an array, the first item will be the default glue, and the second item
will be used instead of the glue for the last item- if $join is true, it will be guessed from the locale ('list' translation file entry)
- if $join is missing, a space will be used as glue if int passed, it add modifiers: Possible values: - CarbonInterface::DIFF_ABSOLUTE no modifiers
- CarbonInterface::DIFF_RELATIVE_TO_NOW add ago/from now modifier
- CarbonInterface::DIFF_RELATIVE_TO_OTHER add before/after modifier Default value: CarbonInterface::DIFF_ABSOLUTE
- $short : bool = false
-
displays short format of time units
- $parts : int = 1
-
maximum number of parts to display (default value: 1: single part)
- $options : int = null
-
human diff options
Return values
stringcalendar()
Returns either day of week + time (e.g. "Last Friday at 3:30 PM") if reference time is within 7 days, or a calendar date (e.g. "10/29/2017") otherwise.
public
calendar([Carbon|DateTimeInterface|string|null $referenceTime = null ][, array<string|int, mixed> $formats = [] ]) : string
Language, date and time formats will change according to the current locale.
Parameters
- $referenceTime : Carbon|DateTimeInterface|string|null = null
- $formats : array<string|int, mixed> = []
Return values
stringcopy()
public
static copy() : void
diff()
public
diff([CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ][, array<string|int, mixed> $skip = [] ]) : CarbonInterval
Parameters
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
- $skip : array<string|int, mixed> = []
Tags
Return values
CarbonIntervaldiffAsCarbonInterval()
Get the difference as a CarbonInterval instance.
public
diffAsCarbonInterval([CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ][, array<string|int, mixed> $skip = [] ]) : CarbonInterval
Return relative interval (negative if $absolute flag is not set to true and the given date is before current one).
Parameters
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
- $skip : array<string|int, mixed> = []
Return values
CarbonIntervaldiffAsDateInterval()
Get the difference as a DateInterval instance.
public
diffAsDateInterval([CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ]) : DateInterval
Return relative interval (negative if $absolute flag is not set to true and the given date is before current one).
Parameters
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
Return values
DateIntervaldiffFiltered()
Get the difference by the given interval using a filter closure.
public
diffFiltered(CarbonInterval $ci, Closure $callback[, CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ]) : int
Parameters
- $ci : CarbonInterval
-
An interval to traverse by
- $callback : Closure
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
Return values
intdiffForHumans()
Get the difference in a human readable format in the current locale from current instance to an other instance given (or now if null given).
public
diffForHumans([Carbon|DateTimeInterface|string|array<string|int, mixed>|null $other = null ][, int|array<string|int, mixed> $syntax = null ][, bool $short = false ][, int $parts = 1 ][, int $options = null ]) : string
Parameters
- $other : Carbon|DateTimeInterface|string|array<string|int, mixed>|null = null
-
if array passed, will be used as parameters array, see $syntax below; if null passed, now will be used as comparison reference; if any other type, it will be converted to date and used as reference.
- $syntax : int|array<string|int, mixed> = null
-
if array passed, parameters will be extracted from it, the array may contains: ⦿ 'syntax' entry (see below) ⦿ 'short' entry (see below) ⦿ 'parts' entry (see below) ⦿ 'options' entry (see below) ⦿ 'skip' entry, list of units to skip (array of strings or a single string,
it can be the unit name (singular or plural) or its shortcut
(y, m, w, d, h, min, s, ms, µs). ⦿ 'aUnit' entry, prefer "an hour" over "1 hour" if true ⦿ 'altNumbers' entry, use alternative numbers if available(from the current language if true is passed, from the given language(s)
if array or string is passed) ⦿ 'join' entry determines how to join multiple parts of the string- if $join is a string, it's used as a joiner glue
- if $join is a callable/closure, it get the list of string and should return a string- if $join is an array, the first item will be the default glue, and the second item
will be used instead of the glue for the last item- if $join is true, it will be guessed from the locale ('list' translation file entry)
- if $join is missing, a space will be used as glue ⦿ 'other' entry (see above) ⦿ 'minimumUnit' entry determines the smallest unit of time to display can be long or ` short form of the units, e.g. 'hour' or 'h' (default value: s) ⦿ 'locale' language in which the diff should be output (has no effect if 'translator' key is set) ⦿ 'translator' a custom translator to use to translator the output. if int passed, it adds modifiers: Possible values:- CarbonInterface::DIFF_ABSOLUTE no modifiers
- CarbonInterface::DIFF_RELATIVE_TO_NOW add ago/from now modifier
- CarbonInterface::DIFF_RELATIVE_TO_OTHER add before/after modifier Default value: CarbonInterface::DIFF_ABSOLUTE
- $short : bool = false
-
displays short format of time units
- $parts : int = 1
-
maximum number of parts to display (default value: 1: single unit)
- $options : int = null
-
human diff options
Tags
Return values
stringdiffInDays()
Get the difference in days.
public
diffInDays([CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ][, bool $utc = false ]) : float
Parameters
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
- $utc : bool = false
-
Always convert dates to UTC before comparing (if not set, it will do it only if timezones are different)
Return values
floatdiffInDaysFiltered()
Get the difference in days using a filter closure.
public
diffInDaysFiltered(Closure $callback[, CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ]) : int
Parameters
- $callback : Closure
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
Return values
intdiffInHours()
Get the difference in hours.
public
diffInHours([CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ]) : float
Parameters
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
Return values
floatdiffInHoursFiltered()
Get the difference in hours using a filter closure.
public
diffInHoursFiltered(Closure $callback[, CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ]) : int
Parameters
- $callback : Closure
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
Return values
intdiffInMicroseconds()
Get the difference in microseconds.
public
diffInMicroseconds([CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ]) : float
Parameters
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
Return values
floatdiffInMilliseconds()
Get the difference in milliseconds.
public
diffInMilliseconds([CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ]) : float
Parameters
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
Return values
floatdiffInMinutes()
Get the difference in minutes.
public
diffInMinutes([CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ]) : float
Parameters
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
Return values
floatdiffInMonths()
Get the difference in months.
public
diffInMonths([CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ][, bool $utc = false ]) : float
Parameters
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
- $utc : bool = false
-
Always convert dates to UTC before comparing (if not set, it will do it only if timezones are different)
Return values
floatdiffInQuarters()
Get the difference in quarters.
public
diffInQuarters([CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ][, bool $utc = false ]) : float
Parameters
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
- $utc : bool = false
-
Always convert dates to UTC before comparing (if not set, it will do it only if timezones are different)
Return values
floatdiffInSeconds()
Get the difference in seconds.
public
diffInSeconds([CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ]) : float
Parameters
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
Return values
floatdiffInUnit()
public
diffInUnit(Unit|string $unit[, CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ][, bool $utc = false ]) : float
Parameters
- $unit : Unit|string
-
microsecond, millisecond, second, minute, hour, day, week, month, quarter, year, century, millennium
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
- $utc : bool = false
-
Always convert dates to UTC before comparing (if not set, it will do it only if timezones are different)
Return values
floatdiffInWeekdays()
Get the difference in weekdays.
public
diffInWeekdays([CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ]) : int
Parameters
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
Return values
intdiffInWeekendDays()
Get the difference in weekend days using a filter.
public
diffInWeekendDays([CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ]) : int
Parameters
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
Return values
intdiffInWeeks()
Get the difference in weeks.
public
diffInWeeks([CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ][, bool $utc = false ]) : float
Parameters
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
- $utc : bool = false
-
Always convert dates to UTC before comparing (if not set, it will do it only if timezones are different)
Return values
floatdiffInYears()
Get the difference in years
public
diffInYears([CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ][, bool $utc = false ]) : float
Parameters
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
- $utc : bool = false
-
Always convert dates to UTC before comparing (if not set, it will do it only if timezones are different)
Return values
floatfrom()
public
from([Carbon|DateTimeInterface|string|array<string|int, mixed>|null $other = null ][, int|array<string|int, mixed> $syntax = null ][, bool $short = false ][, int $parts = 1 ][, int $options = null ]) : string
Parameters
- $other : Carbon|DateTimeInterface|string|array<string|int, mixed>|null = null
-
if array passed, will be used as parameters array, see $syntax below; if null passed, now will be used as comparison reference; if any other type, it will be converted to date and used as reference.
- $syntax : int|array<string|int, mixed> = null
-
if array passed, parameters will be extracted from it, the array may contains:
- 'syntax' entry (see below)
- 'short' entry (see below)
- 'parts' entry (see below)
- 'options' entry (see below)
- 'join' entry determines how to join multiple parts of the string
- if $join is a string, it's used as a joiner glue
- if $join is a callable/closure, it get the list of string and should return a string- if $join is an array, the first item will be the default glue, and the second item
will be used instead of the glue for the last item- if $join is true, it will be guessed from the locale ('list' translation file entry)
- if $join is missing, a space will be used as glue - 'other' entry (see above) if int passed, it add modifiers: Possible values:
- CarbonInterface::DIFF_ABSOLUTE no modifiers
- CarbonInterface::DIFF_RELATIVE_TO_NOW add ago/from now modifier
- CarbonInterface::DIFF_RELATIVE_TO_OTHER add before/after modifier Default value: CarbonInterface::DIFF_ABSOLUTE
- $short : bool = false
-
displays short format of time units
- $parts : int = 1
-
maximum number of parts to display (default value: 1: single unit)
- $options : int = null
-
human diff options
Tags
Return values
stringfromNow()
Get the difference in a human readable format in the current locale from current instance to now.
public
fromNow([int|array<string|int, mixed> $syntax = null ][, bool $short = false ][, int $parts = 1 ][, int $options = null ]) : string
Parameters
- $syntax : int|array<string|int, mixed> = null
-
if array passed, parameters will be extracted from it, the array may contains:
- 'syntax' entry (see below)
- 'short' entry (see below)
- 'parts' entry (see below)
- 'options' entry (see below)
- 'join' entry determines how to join multiple parts of the string
- if $join is a string, it's used as a joiner glue
- if $join is a callable/closure, it get the list of string and should return a string- if $join is an array, the first item will be the default glue, and the second item
will be used instead of the glue for the last item- if $join is true, it will be guessed from the locale ('list' translation file entry)
- if $join is missing, a space will be used as glue if int passed, it add modifiers: Possible values: - CarbonInterface::DIFF_ABSOLUTE no modifiers
- CarbonInterface::DIFF_RELATIVE_TO_NOW add ago/from now modifier
- CarbonInterface::DIFF_RELATIVE_TO_OTHER add before/after modifier Default value: CarbonInterface::DIFF_ABSOLUTE
- $short : bool = false
-
displays short format of time units
- $parts : int = 1
-
maximum number of parts to display (default value: 1: single unit)
- $options : int = null
-
human diff options
Return values
stringlessThan()
public
lessThan(mixed $date) : bool
Parameters
- $date : mixed
Return values
boolresolveCarbon()
public
static resolveCarbon(mixed $date) : void
Parameters
- $date : mixed
secondsSinceMidnight()
The number of seconds since midnight.
public
secondsSinceMidnight() : float
Return values
floatsecondsUntilEndOfDay()
The number of seconds until 23:59:59.
public
secondsUntilEndOfDay() : float
Return values
floatsince()
public
since([mixed $other = null ][, mixed $syntax = null ][, mixed $short = false ][, mixed $parts = 1 ][, mixed $options = null ]) : mixed
Parameters
- $other : mixed = null
- $syntax : mixed = null
- $short : mixed = false
- $parts : mixed = 1
- $options : mixed = null
Tags
timespan()
Get the difference in a human-readable format in the current locale from current instance to another instance given (or now if null given).
public
timespan([mixed $other = null ][, mixed $timezone = null ]) : string
Parameters
- $other : mixed = null
- $timezone : mixed = null
Return values
stringto()
Get the difference in a human readable format in the current locale from an other instance given (or now if null given) to current instance.
public
to([Carbon|DateTimeInterface|string|array<string|int, mixed>|null $other = null ][, int|array<string|int, mixed> $syntax = null ][, bool $short = false ][, int $parts = 1 ][, int $options = null ]) : string
When comparing a value in the past to default now: 1 hour from now 5 months from now
When comparing a value in the future to default now: 1 hour ago 5 months ago
When comparing a value in the past to another value: 1 hour after 5 months after
When comparing a value in the future to another value: 1 hour before 5 months before
Parameters
- $other : Carbon|DateTimeInterface|string|array<string|int, mixed>|null = null
-
if array passed, will be used as parameters array, see $syntax below; if null passed, now will be used as comparison reference; if any other type, it will be converted to date and used as reference.
- $syntax : int|array<string|int, mixed> = null
-
if array passed, parameters will be extracted from it, the array may contains:
- 'syntax' entry (see below)
- 'short' entry (see below)
- 'parts' entry (see below)
- 'options' entry (see below)
- 'join' entry determines how to join multiple parts of the string
- if $join is a string, it's used as a joiner glue
- if $join is a callable/closure, it get the list of string and should return a string- if $join is an array, the first item will be the default glue, and the second item
will be used instead of the glue for the last item- if $join is true, it will be guessed from the locale ('list' translation file entry)
- if $join is missing, a space will be used as glue - 'other' entry (see above) if int passed, it add modifiers: Possible values:
- CarbonInterface::DIFF_ABSOLUTE no modifiers
- CarbonInterface::DIFF_RELATIVE_TO_NOW add ago/from now modifier
- CarbonInterface::DIFF_RELATIVE_TO_OTHER add before/after modifier Default value: CarbonInterface::DIFF_ABSOLUTE
- $short : bool = false
-
displays short format of time units
- $parts : int = 1
-
maximum number of parts to display (default value: 1: single unit)
- $options : int = null
-
human diff options
Return values
stringtoNow()
Get the difference in a human readable format in the current locale from an other instance given to now
public
toNow([int|array<string|int, mixed> $syntax = null ][, bool $short = false ][, int $parts = 1 ][, int $options = null ]) : string
Parameters
- $syntax : int|array<string|int, mixed> = null
-
if array passed, parameters will be extracted from it, the array may contains:
- 'syntax' entry (see below)
- 'short' entry (see below)
- 'parts' entry (see below)
- 'options' entry (see below)
- 'join' entry determines how to join multiple parts of the string
- if $join is a string, it's used as a joiner glue
- if $join is a callable/closure, it get the list of string and should return a string- if $join is an array, the first item will be the default glue, and the second item
will be used instead of the glue for the last item- if $join is true, it will be guessed from the locale ('list' translation file entry)
- if $join is missing, a space will be used as glue if int passed, it add modifiers: Possible values: - CarbonInterface::DIFF_ABSOLUTE no modifiers
- CarbonInterface::DIFF_RELATIVE_TO_NOW add ago/from now modifier
- CarbonInterface::DIFF_RELATIVE_TO_OTHER add before/after modifier Default value: CarbonInterface::DIFF_ABSOLUTE
- $short : bool = false
-
displays short format of time units
- $parts : int = 1
-
maximum number of parts to display (default value: 1: single part)
- $options : int = null
-
human diff options
Return values
stringuntil()
public
until([Carbon|DateTimeInterface|string|array<string|int, mixed>|null $other = null ][, int|array<string|int, mixed> $syntax = null ][, bool $short = false ][, int $parts = 1 ][, int $options = null ]) : string
Parameters
- $other : Carbon|DateTimeInterface|string|array<string|int, mixed>|null = null
-
if array passed, will be used as parameters array, see $syntax below; if null passed, now will be used as comparison reference; if any other type, it will be converted to date and used as reference.
- $syntax : int|array<string|int, mixed> = null
-
if array passed, parameters will be extracted from it, the array may contains:
- 'syntax' entry (see below)
- 'short' entry (see below)
- 'parts' entry (see below)
- 'options' entry (see below)
- 'join' entry determines how to join multiple parts of the string
- if $join is a string, it's used as a joiner glue
- if $join is a callable/closure, it get the list of string and should return a string- if $join is an array, the first item will be the default glue, and the second item
will be used instead of the glue for the last item- if $join is true, it will be guessed from the locale ('list' translation file entry)
- if $join is missing, a space will be used as glue - 'other' entry (see above) if int passed, it add modifiers: Possible values:
- CarbonInterface::DIFF_ABSOLUTE no modifiers
- CarbonInterface::DIFF_RELATIVE_TO_NOW add ago/from now modifier
- CarbonInterface::DIFF_RELATIVE_TO_OTHER add before/after modifier Default value: CarbonInterface::DIFF_ABSOLUTE
- $short : bool = false
-
displays short format of time units
- $parts : int = 1
-
maximum number of parts to display (default value: 1: single unit)
- $options : int = null
-
human diff options
Tags
Return values
stringgetIntervalDayDiff()
private
getIntervalDayDiff(DateInterval $interval) : int
Parameters
- $interval : DateInterval