FileAccess Orion

Comparison

Trait Comparison.

Comparison utils and testers. All the following methods return booleans. nowWithSameTz

Depends on the following methods:

Table of Contents

between()  : bool
Determines if the instance is between two others.
betweenExcluded()  : bool
Determines if the instance is between two others, bounds excluded.
betweenIncluded()  : bool
Determines if the instance is between two others, bounds included.
copy()  : CarbonInterface
eq()  : bool
Determines if the instance is equal to another
equalTo()  : bool
Determines if the instance is equal to another
greaterThan()  : bool
Determines if the instance is greater (after) than another
greaterThanOrEqualTo()  : bool
Determines if the instance is greater (after) than or equal to another
gt()  : bool
Determines if the instance is greater (after) than another
gte()  : bool
Determines if the instance is greater (after) than or equal to another
hasFormat()  : bool
Checks if the (date)time string is in a given format.
is()  : bool
Returns true if the current date matches the given string.
isAfter()  : bool
Determines if the instance is greater (after) than another
isBefore()  : bool
Determines if the instance is less (before) than another
isBetween()  : bool
Determines if the instance is between two others
isBirthday()  : bool
Check if its the birthday. Compares the date/month values of the two dates.
isCurrentUnit()  : bool
Determines if the instance is in the current unit given.
isDayOfWeek()  : bool
Checks if this day is a specific day of the week.
isEndOfDay()  : bool
Check if the instance is end of day.
isFuture()  : bool
Determines if the instance is in the future, ie. greater (after) than now.
isLastOfMonth()  : bool
Check if today is the last day of the Month
isLeapYear()  : bool
Determines if the instance is a leap year.
isLongYear()  : bool
Determines if the instance is a long year
isMidday()  : bool
Check if the instance is midday.
isMidnight()  : bool
Check if the instance is start of day / midnight.
isPast()  : bool
Determines if the instance is in the past, ie. less (before) than now.
isSameAs()  : bool
Compares the formatted values of the two dates.
isSameMonth()  : bool
Checks if the passed in date is in the same month as the instance´s month.
isSameQuarter()  : bool
Checks if the passed in date is in the same quarter as the instance quarter (and year if needed).
isSameUnit()  : bool
Determines if the instance is in the current unit given.
isStartOfDay()  : bool
Check if the instance is start of day / midnight.
isToday()  : bool
Determines if the instance is today.
isTomorrow()  : bool
Determines if the instance is tomorrow.
isWeekday()  : bool
Determines if the instance is a weekday.
isWeekend()  : bool
Determines if the instance is a weekend day.
isYesterday()  : bool
Determines if the instance is yesterday.
lessThan()  : bool
Determines if the instance is less (before) than another
lessThanOrEqualTo()  : bool
Determines if the instance is less (before) or equal to another
lt()  : bool
Determines if the instance is less (before) than another
lte()  : bool
Determines if the instance is less (before) or equal to another
ne()  : bool
Determines if the instance is not equal to another
notEqualTo()  : bool
Determines if the instance is not equal to another
nowWithSameTz()  : CarbonInterface
resolveCarbon()  : CarbonInterface
tomorrow()  : CarbonInterface
yesterday()  : CarbonInterface

Methods

between()

Determines if the instance is between two others.

public between(Carbon|DateTimeInterface|mixed $date1, Carbon|DateTimeInterface|mixed $date2[, bool $equal = true ]) : bool

The third argument allow you to specify if bounds are included or not (true by default) but for when you including/excluding bounds may produce different results in your application, we recommend to use the explicit methods ->betweenIncluded() or ->betweenExcluded() instead.

Parameters
$date1 : Carbon|DateTimeInterface|mixed
$date2 : Carbon|DateTimeInterface|mixed
$equal : bool = true

Indicates if an equal to comparison should be done

Tags
example
Carbon::parse('2018-07-25')->between('2018-07-14', '2018-08-01'); // true
Carbon::parse('2018-07-25')->between('2018-08-01', '2018-08-20'); // false
Carbon::parse('2018-07-25')->between('2018-07-25', '2018-08-01'); // true
Carbon::parse('2018-07-25')->between('2018-07-25', '2018-08-01', false); // false
Return values
bool

betweenExcluded()

Determines if the instance is between two others, bounds excluded.

public betweenExcluded(Carbon|DateTimeInterface|mixed $date1, Carbon|DateTimeInterface|mixed $date2) : bool
Parameters
$date1 : Carbon|DateTimeInterface|mixed
$date2 : Carbon|DateTimeInterface|mixed
Tags
example
Carbon::parse('2018-07-25')->betweenExcluded('2018-07-14', '2018-08-01'); // true
Carbon::parse('2018-07-25')->betweenExcluded('2018-08-01', '2018-08-20'); // false
Carbon::parse('2018-07-25')->betweenExcluded('2018-07-25', '2018-08-01'); // false
Return values
bool

betweenIncluded()

Determines if the instance is between two others, bounds included.

public betweenIncluded(Carbon|DateTimeInterface|mixed $date1, Carbon|DateTimeInterface|mixed $date2) : bool
Parameters
$date1 : Carbon|DateTimeInterface|mixed
$date2 : Carbon|DateTimeInterface|mixed
Tags
example
Carbon::parse('2018-07-25')->betweenIncluded('2018-07-14', '2018-08-01'); // true
Carbon::parse('2018-07-25')->betweenIncluded('2018-08-01', '2018-08-20'); // false
Carbon::parse('2018-07-25')->betweenIncluded('2018-07-25', '2018-08-01'); // true
Return values
bool

eq()

Determines if the instance is equal to another

public eq(Carbon|DateTimeInterface|mixed $date) : bool
Parameters
$date : Carbon|DateTimeInterface|mixed
Tags
example
Carbon::parse('2018-07-25 12:45:16')->eq('2018-07-25 12:45:16'); // true
Carbon::parse('2018-07-25 12:45:16')->eq(Carbon::parse('2018-07-25 12:45:16')); // true
Carbon::parse('2018-07-25 12:45:16')->eq('2018-07-25 12:45:17'); // false
see
equalTo()
Return values
bool

equalTo()

Determines if the instance is equal to another

public equalTo(Carbon|DateTimeInterface|mixed $date) : bool
Parameters
$date : Carbon|DateTimeInterface|mixed
Tags
example
Carbon::parse('2018-07-25 12:45:16')->equalTo('2018-07-25 12:45:16'); // true
Carbon::parse('2018-07-25 12:45:16')->equalTo(Carbon::parse('2018-07-25 12:45:16')); // true
Carbon::parse('2018-07-25 12:45:16')->equalTo('2018-07-25 12:45:17'); // false
Return values
bool

greaterThan()

Determines if the instance is greater (after) than another

public greaterThan(Carbon|DateTimeInterface|mixed $date) : bool
Parameters
$date : Carbon|DateTimeInterface|mixed
Tags
example
Carbon::parse('2018-07-25 12:45:16')->greaterThan('2018-07-25 12:45:15'); // true
Carbon::parse('2018-07-25 12:45:16')->greaterThan('2018-07-25 12:45:16'); // false
Carbon::parse('2018-07-25 12:45:16')->greaterThan('2018-07-25 12:45:17'); // false
Return values
bool

greaterThanOrEqualTo()

Determines if the instance is greater (after) than or equal to another

public greaterThanOrEqualTo(Carbon|DateTimeInterface|mixed $date) : bool
Parameters
$date : Carbon|DateTimeInterface|mixed
Tags
example
Carbon::parse('2018-07-25 12:45:16')->greaterThanOrEqualTo('2018-07-25 12:45:15'); // true
Carbon::parse('2018-07-25 12:45:16')->greaterThanOrEqualTo('2018-07-25 12:45:16'); // true
Carbon::parse('2018-07-25 12:45:16')->greaterThanOrEqualTo('2018-07-25 12:45:17'); // false
Return values
bool

gt()

Determines if the instance is greater (after) than another

public gt(Carbon|DateTimeInterface|mixed $date) : bool
Parameters
$date : Carbon|DateTimeInterface|mixed
Tags
example
Carbon::parse('2018-07-25 12:45:16')->gt('2018-07-25 12:45:15'); // true
Carbon::parse('2018-07-25 12:45:16')->gt('2018-07-25 12:45:16'); // false
Carbon::parse('2018-07-25 12:45:16')->gt('2018-07-25 12:45:17'); // false
see
greaterThan()
Return values
bool

gte()

Determines if the instance is greater (after) than or equal to another

public gte(Carbon|DateTimeInterface|mixed $date) : bool
Parameters
$date : Carbon|DateTimeInterface|mixed
Tags
example
Carbon::parse('2018-07-25 12:45:16')->gte('2018-07-25 12:45:15'); // true
Carbon::parse('2018-07-25 12:45:16')->gte('2018-07-25 12:45:16'); // true
Carbon::parse('2018-07-25 12:45:16')->gte('2018-07-25 12:45:17'); // false
see
greaterThanOrEqualTo()
Return values
bool

hasFormat()

Checks if the (date)time string is in a given format.

public static hasFormat(string $date, string $format) : bool
Parameters
$date : string
$format : string
Tags
example
Carbon::hasFormat('11:12:45', 'h:i:s'); // true
Carbon::hasFormat('13:12:45', 'h:i:s'); // false
SuppressWarnings

(PHPMD.EmptyCatchBlock)

Return values
bool

is()

Returns true if the current date matches the given string.

public is(string $tester) : bool
Parameters
$tester : string

day name, month name, hour, date, etc. as string

Tags
example
var_dump(Carbon::parse('2019-06-02 12:23:45')->is('2019')); // true
var_dump(Carbon::parse('2019-06-02 12:23:45')->is('2018')); // false
var_dump(Carbon::parse('2019-06-02 12:23:45')->is('2019-06')); // true
var_dump(Carbon::parse('2019-06-02 12:23:45')->is('06-02')); // true
var_dump(Carbon::parse('2019-06-02 12:23:45')->is('2019-06-02')); // true
var_dump(Carbon::parse('2019-06-02 12:23:45')->is('Sunday')); // true
var_dump(Carbon::parse('2019-06-02 12:23:45')->is('June')); // true
var_dump(Carbon::parse('2019-06-02 12:23:45')->is('12:23')); // true
var_dump(Carbon::parse('2019-06-02 12:23:45')->is('12:23:45')); // true
var_dump(Carbon::parse('2019-06-02 12:23:45')->is('12:23:00')); // false
var_dump(Carbon::parse('2019-06-02 12:23:45')->is('12h')); // true
var_dump(Carbon::parse('2019-06-02 15:23:45')->is('3pm')); // true
var_dump(Carbon::parse('2019-06-02 15:23:45')->is('3am')); // false
Return values
bool

isAfter()

Determines if the instance is greater (after) than another

public isAfter(Carbon|DateTimeInterface|mixed $date) : bool
Parameters
$date : Carbon|DateTimeInterface|mixed
Tags
example
Carbon::parse('2018-07-25 12:45:16')->isAfter('2018-07-25 12:45:15'); // true
Carbon::parse('2018-07-25 12:45:16')->isAfter('2018-07-25 12:45:16'); // false
Carbon::parse('2018-07-25 12:45:16')->isAfter('2018-07-25 12:45:17'); // false
see
greaterThan()
Return values
bool

isBefore()

Determines if the instance is less (before) than another

public isBefore(Carbon|DateTimeInterface|mixed $date) : bool
Parameters
$date : Carbon|DateTimeInterface|mixed
Tags
example
Carbon::parse('2018-07-25 12:45:16')->isBefore('2018-07-25 12:45:15'); // false
Carbon::parse('2018-07-25 12:45:16')->isBefore('2018-07-25 12:45:16'); // false
Carbon::parse('2018-07-25 12:45:16')->isBefore('2018-07-25 12:45:17'); // true
see
lessThan()
Return values
bool

isBetween()

Determines if the instance is between two others

public isBetween(Carbon|DateTimeInterface|mixed $date1, Carbon|DateTimeInterface|mixed $date2[, bool $equal = true ]) : bool
Parameters
$date1 : Carbon|DateTimeInterface|mixed
$date2 : Carbon|DateTimeInterface|mixed
$equal : bool = true

Indicates if an equal to comparison should be done

Tags
example
Carbon::parse('2018-07-25')->isBetween('2018-07-14', '2018-08-01'); // true
Carbon::parse('2018-07-25')->isBetween('2018-08-01', '2018-08-20'); // false
Carbon::parse('2018-07-25')->isBetween('2018-07-25', '2018-08-01'); // true
Carbon::parse('2018-07-25')->isBetween('2018-07-25', '2018-08-01', false); // false
Return values
bool

isBirthday()

Check if its the birthday. Compares the date/month values of the two dates.

public isBirthday([Carbon|DateTimeInterface|null $date = null ]) : bool
Parameters
$date : Carbon|DateTimeInterface|null = null

The instance to compare with or null to use current day.

Tags
example
Carbon::now()->subYears(5)->isBirthday(); // true
Carbon::now()->subYears(5)->subDay()->isBirthday(); // false
Carbon::parse('2019-06-05')->isBirthday(Carbon::parse('2001-06-05')); // true
Carbon::parse('2019-06-05')->isBirthday(Carbon::parse('2001-06-06')); // false
Return values
bool

isCurrentUnit()

Determines if the instance is in the current unit given.

public isCurrentUnit(string $unit) : bool
Parameters
$unit : string

The unit to test.

Tags
example
Carbon::now()->isCurrentUnit('hour'); // true
Carbon::now()->subHours(2)->isCurrentUnit('hour'); // false
throws
BadMethodCallException
Return values
bool

isDayOfWeek()

Checks if this day is a specific day of the week.

public isDayOfWeek(int $dayOfWeek) : bool
Parameters
$dayOfWeek : int
Tags
example
Carbon::parse('2019-07-17')->isDayOfWeek(Carbon::WEDNESDAY); // true
Carbon::parse('2019-07-17')->isDayOfWeek(Carbon::FRIDAY); // false
Carbon::parse('2019-07-17')->isDayOfWeek('Wednesday'); // true
Carbon::parse('2019-07-17')->isDayOfWeek('Friday'); // false
Return values
bool

isEndOfDay()

Check if the instance is end of day.

public isEndOfDay([bool $checkMicroseconds = false ]) : bool
Parameters
$checkMicroseconds : bool = false

check time at microseconds precision

Tags
example
Carbon::parse('2019-02-28 23:59:59.999999')->isEndOfDay(); // true
Carbon::parse('2019-02-28 23:59:59.123456')->isEndOfDay(); // true
Carbon::parse('2019-02-28 23:59:59')->isEndOfDay(); // true
Carbon::parse('2019-02-28 23:59:58.999999')->isEndOfDay(); // false
Carbon::parse('2019-02-28 23:59:59.999999')->isEndOfDay(true); // true
Carbon::parse('2019-02-28 23:59:59.123456')->isEndOfDay(true); // false
Carbon::parse('2019-02-28 23:59:59')->isEndOfDay(true); // false
Return values
bool

isFuture()

Determines if the instance is in the future, ie. greater (after) than now.

public isFuture() : bool
Tags
example
Carbon::now()->addHours(5)->isFuture(); // true
Carbon::now()->subHours(5)->isFuture(); // false
Return values
bool

isLastOfMonth()

Check if today is the last day of the Month

public isLastOfMonth() : bool
Tags
example
Carbon::parse('2019-02-28')->isLastOfMonth(); // true
Carbon::parse('2019-03-28')->isLastOfMonth(); // false
Carbon::parse('2019-03-30')->isLastOfMonth(); // false
Carbon::parse('2019-03-31')->isLastOfMonth(); // true
Carbon::parse('2019-04-30')->isLastOfMonth(); // true
Return values
bool

isLeapYear()

Determines if the instance is a leap year.

public isLeapYear() : bool
Tags
example
Carbon::parse('2020-01-01')->isLeapYear(); // true
Carbon::parse('2019-01-01')->isLeapYear(); // false
Return values
bool

isMidday()

Check if the instance is midday.

public isMidday() : bool
Tags
example
Carbon::parse('2019-02-28 11:59:59.999999')->isMidday(); // false
Carbon::parse('2019-02-28 12:00:00')->isMidday(); // true
Carbon::parse('2019-02-28 12:00:00.999999')->isMidday(); // true
Carbon::parse('2019-02-28 12:00:01')->isMidday(); // false
Return values
bool

isMidnight()

Check if the instance is start of day / midnight.

public isMidnight() : bool
Tags
example
Carbon::parse('2019-02-28 00:00:00')->isMidnight(); // true
Carbon::parse('2019-02-28 00:00:00.999999')->isMidnight(); // true
Carbon::parse('2019-02-28 00:00:01')->isMidnight(); // false
Return values
bool

isPast()

Determines if the instance is in the past, ie. less (before) than now.

public isPast() : bool
Tags
example
Carbon::now()->subHours(5)->isPast(); // true
Carbon::now()->addHours(5)->isPast(); // false
Return values
bool

isSameAs()

Compares the formatted values of the two dates.

public isSameAs(string $format[, Carbon|DateTimeInterface|string|null $date = null ]) : bool
Parameters
$format : string

date formats to compare.

$date : Carbon|DateTimeInterface|string|null = null

instance to compare with or null to use current day.

Tags
example
Carbon::parse('2019-06-13')->isSameAs('Y-d', Carbon::parse('2019-12-13')); // true
Carbon::parse('2019-06-13')->isSameAs('Y-d', Carbon::parse('2019-06-14')); // false
Return values
bool

isSameMonth()

Checks if the passed in date is in the same month as the instance´s month.

public isSameMonth([Carbon|DateTimeInterface|null $date = null ][, bool $ofSameYear = true ]) : bool
Parameters
$date : Carbon|DateTimeInterface|null = null

The instance to compare with or null to use the current date.

$ofSameYear : bool = true

Check if it is the same month in the same year.

Tags
example
Carbon::parse('2019-01-12')->isSameMonth(Carbon::parse('2019-01-01')); // true
Carbon::parse('2019-01-12')->isSameMonth(Carbon::parse('2019-02-01')); // false
Carbon::parse('2019-01-12')->isSameMonth(Carbon::parse('2018-01-01')); // false
Carbon::parse('2019-01-12')->isSameMonth(Carbon::parse('2018-01-01'), false); // true
Return values
bool

isSameQuarter()

Checks if the passed in date is in the same quarter as the instance quarter (and year if needed).

public isSameQuarter([Carbon|DateTimeInterface|string|null $date = null ][, bool $ofSameYear = true ]) : bool
Parameters
$date : Carbon|DateTimeInterface|string|null = null

The instance to compare with or null to use current day.

$ofSameYear : bool = true

Check if it is the same month in the same year.

Tags
example
Carbon::parse('2019-01-12')->isSameQuarter(Carbon::parse('2019-03-01')); // true
Carbon::parse('2019-01-12')->isSameQuarter(Carbon::parse('2019-04-01')); // false
Carbon::parse('2019-01-12')->isSameQuarter(Carbon::parse('2018-03-01')); // false
Carbon::parse('2019-01-12')->isSameQuarter(Carbon::parse('2018-03-01'), false); // true
Return values
bool

isSameUnit()

Determines if the instance is in the current unit given.

public isSameUnit(string $unit[, Carbon|DateTimeInterface|null $date = null ]) : bool
Parameters
$unit : string

singular unit string

$date : Carbon|DateTimeInterface|null = null

instance to compare with or null to use current day.

Tags
example
Carbon::parse('2019-01-13')->isSameUnit('year', Carbon::parse('2019-12-25')); // true
Carbon::parse('2018-12-13')->isSameUnit('year', Carbon::parse('2019-12-25')); // false
throws
BadComparisonUnitException
Return values
bool

isStartOfDay()

Check if the instance is start of day / midnight.

public isStartOfDay([bool $checkMicroseconds = false ]) : bool
Parameters
$checkMicroseconds : bool = false

check time at microseconds precision

Tags
example
Carbon::parse('2019-02-28 00:00:00')->isStartOfDay(); // true
Carbon::parse('2019-02-28 00:00:00.999999')->isStartOfDay(); // true
Carbon::parse('2019-02-28 00:00:01')->isStartOfDay(); // false
Carbon::parse('2019-02-28 00:00:00.000000')->isStartOfDay(true); // true
Carbon::parse('2019-02-28 00:00:00.000012')->isStartOfDay(true); // false
Return values
bool

isToday()

Determines if the instance is today.

public isToday() : bool
Tags
example
Carbon::today()->isToday(); // true
Carbon::tomorrow()->isToday(); // false
Return values
bool

isTomorrow()

Determines if the instance is tomorrow.

public isTomorrow() : bool
Tags
example
Carbon::tomorrow()->isTomorrow(); // true
Carbon::yesterday()->isTomorrow(); // false
Return values
bool

isWeekday()

Determines if the instance is a weekday.

public isWeekday() : bool
Tags
example
Carbon::parse('2019-07-14')->isWeekday(); // false
Carbon::parse('2019-07-15')->isWeekday(); // true
Return values
bool

isWeekend()

Determines if the instance is a weekend day.

public isWeekend() : bool
Tags
example
Carbon::parse('2019-07-14')->isWeekend(); // true
Carbon::parse('2019-07-15')->isWeekend(); // false
Return values
bool

isYesterday()

Determines if the instance is yesterday.

public isYesterday() : bool
Tags
example
Carbon::yesterday()->isYesterday(); // true
Carbon::tomorrow()->isYesterday(); // false
Return values
bool

lessThan()

Determines if the instance is less (before) than another

public lessThan(Carbon|DateTimeInterface|mixed $date) : bool
Parameters
$date : Carbon|DateTimeInterface|mixed
Tags
example
Carbon::parse('2018-07-25 12:45:16')->lessThan('2018-07-25 12:45:15'); // false
Carbon::parse('2018-07-25 12:45:16')->lessThan('2018-07-25 12:45:16'); // false
Carbon::parse('2018-07-25 12:45:16')->lessThan('2018-07-25 12:45:17'); // true
Return values
bool

lessThanOrEqualTo()

Determines if the instance is less (before) or equal to another

public lessThanOrEqualTo(Carbon|DateTimeInterface|mixed $date) : bool
Parameters
$date : Carbon|DateTimeInterface|mixed
Tags
example
Carbon::parse('2018-07-25 12:45:16')->lessThanOrEqualTo('2018-07-25 12:45:15'); // false
Carbon::parse('2018-07-25 12:45:16')->lessThanOrEqualTo('2018-07-25 12:45:16'); // true
Carbon::parse('2018-07-25 12:45:16')->lessThanOrEqualTo('2018-07-25 12:45:17'); // true
Return values
bool

lt()

Determines if the instance is less (before) than another

public lt(Carbon|DateTimeInterface|mixed $date) : bool
Parameters
$date : Carbon|DateTimeInterface|mixed
Tags
example
Carbon::parse('2018-07-25 12:45:16')->lt('2018-07-25 12:45:15'); // false
Carbon::parse('2018-07-25 12:45:16')->lt('2018-07-25 12:45:16'); // false
Carbon::parse('2018-07-25 12:45:16')->lt('2018-07-25 12:45:17'); // true
see
lessThan()
Return values
bool

lte()

Determines if the instance is less (before) or equal to another

public lte(Carbon|DateTimeInterface|mixed $date) : bool
Parameters
$date : Carbon|DateTimeInterface|mixed
Tags
example
Carbon::parse('2018-07-25 12:45:16')->lte('2018-07-25 12:45:15'); // false
Carbon::parse('2018-07-25 12:45:16')->lte('2018-07-25 12:45:16'); // true
Carbon::parse('2018-07-25 12:45:16')->lte('2018-07-25 12:45:17'); // true
see
lessThanOrEqualTo()
Return values
bool

ne()

Determines if the instance is not equal to another

public ne(Carbon|DateTimeInterface|mixed $date) : bool
Parameters
$date : Carbon|DateTimeInterface|mixed
Tags
example
Carbon::parse('2018-07-25 12:45:16')->ne('2018-07-25 12:45:16'); // false
Carbon::parse('2018-07-25 12:45:16')->ne(Carbon::parse('2018-07-25 12:45:16')); // false
Carbon::parse('2018-07-25 12:45:16')->ne('2018-07-25 12:45:17'); // true
see
notEqualTo()
Return values
bool

notEqualTo()

Determines if the instance is not equal to another

public notEqualTo(Carbon|DateTimeInterface|mixed $date) : bool
Parameters
$date : Carbon|DateTimeInterface|mixed
Tags
example
Carbon::parse('2018-07-25 12:45:16')->notEqualTo('2018-07-25 12:45:16'); // false
Carbon::parse('2018-07-25 12:45:16')->notEqualTo(Carbon::parse('2018-07-25 12:45:16')); // false
Carbon::parse('2018-07-25 12:45:16')->notEqualTo('2018-07-25 12:45:17'); // true
Return values
bool

Search results