Pionia Core

Comparison

Trait Comparison.

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

Depends on the following methods:

Table of Contents

Properties

$endOfTime  : bool
$startOfTime  : bool

Methods

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.
canBeCreatedFromFormat()  : bool
Checks if the (date)time string is in a given format and valid to create a new instance.
copy()  : void
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.
hasFormatWithModifiers()  : 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.
isEndOfCentury()  : bool
Determines if the instance is end of century (last day by default but interval can be customized).
isEndOfDay()  : bool
Check if the instance is end of day.
isEndOfDecade()  : bool
Determines if the instance is end of decade (last day by default but interval can be customized).
isEndOfHour()  : bool
Determines if the instance is end of hour (last microsecond by default but interval can be customized).
isEndOfMillennium()  : bool
Determines if the instance is end of millennium (last day by default but interval can be customized).
isEndOfMillisecond()  : bool
Determines if the instance is end of millisecond (last microsecond by default but interval can be customized).
isEndOfMinute()  : bool
Determines if the instance is end of minute (last microsecond by default but interval can be customized).
isEndOfMonth()  : bool
Determines if the instance is end of month (last day by default but interval can be customized).
isEndOfQuarter()  : bool
Determines if the instance is end of quarter (last day by default but interval can be customized).
isEndOfSecond()  : bool
Determines if the instance is end of second (last microsecond by default but interval can be customized).
isEndOfTime()  : bool
Returns true if the date was created using CarbonImmutable::endOfTime()
isEndOfUnit()  : bool
Check if the instance is end of a given unit (tolerating a given interval).
isEndOfWeek()  : bool
Determines if the instance is end of week (last day by default but interval can be customized).
isEndOfYear()  : bool
Determines if the instance is end of year (last day by default but interval can be customized).
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.
isLongIsoYear()  : bool
Determines if the instance is a long year (using ISO 8601 year).
isLongYear()  : bool
Determines if the instance is a long year (using calendar 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.
isStartOfCentury()  : bool
Determines if the instance is start of century (first day by default but interval can be customized).
isStartOfDay()  : bool
Check if the instance is start of day / midnight.
isStartOfDecade()  : bool
Determines if the instance is start of decade (first day by default but interval can be customized).
isStartOfHour()  : bool
Determines if the instance is start of hour (first microsecond by default but interval can be customized).
isStartOfMillennium()  : bool
Determines if the instance is start of millennium (first day by default but interval can be customized).
isStartOfMillisecond()  : bool
Determines if the instance is start of millisecond (first microsecond by default but interval can be customized).
isStartOfMinute()  : bool
Determines if the instance is start of minute (first microsecond by default but interval can be customized).
isStartOfMonth()  : bool
Determines if the instance is start of month (first day by default but interval can be customized).
isStartOfQuarter()  : bool
Determines if the instance is start of quarter (first day by default but interval can be customized).
isStartOfSecond()  : bool
Determines if the instance is start of second (first microsecond by default but interval can be customized).
isStartOfTime()  : bool
Returns true if the date was created using CarbonImmutable::startOfTime()
isStartOfUnit()  : bool
Check if the instance is start of a given unit (tolerating a given interval).
isStartOfWeek()  : bool
Determines if the instance is start of week (first day by default but interval can be customized).
isStartOfYear()  : bool
Determines if the instance is start of year (first day by default but interval can be customized).
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()  : void
resolveCarbon()  : void
tomorrow()  : static
yesterday()  : static

Properties

$startOfTime

protected bool $startOfTime = false

Methods

between()

Determines if the instance is between two others.

public between(DateTimeInterface|string $date1, DateTimeInterface|string $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 : DateTimeInterface|string
$date2 : DateTimeInterface|string
$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(DateTimeInterface|string $date1, DateTimeInterface|string $date2) : bool
Parameters
$date1 : DateTimeInterface|string
$date2 : DateTimeInterface|string
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(DateTimeInterface|string $date1, DateTimeInterface|string $date2) : bool
Parameters
$date1 : DateTimeInterface|string
$date2 : DateTimeInterface|string
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

canBeCreatedFromFormat()

Checks if the (date)time string is in a given format and valid to create a new instance.

public static canBeCreatedFromFormat(string|null $date, string $format) : bool
Parameters
$date : string|null
$format : string
Tags
example
Carbon::canBeCreatedFromFormat('11:12:45', 'h:i:s'); // true
Carbon::canBeCreatedFromFormat('13:12:45', 'h:i:s'); // false
Return values
bool

eq()

Determines if the instance is equal to another

public eq(DateTimeInterface|string $date) : bool
Parameters
$date : DateTimeInterface|string
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(DateTimeInterface|string $date) : bool
Parameters
$date : DateTimeInterface|string
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(DateTimeInterface|string $date) : bool
Parameters
$date : DateTimeInterface|string
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(DateTimeInterface|string $date) : bool
Parameters
$date : DateTimeInterface|string
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(DateTimeInterface|string $date) : bool
Parameters
$date : DateTimeInterface|string
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(DateTimeInterface|string $date) : bool
Parameters
$date : DateTimeInterface|string
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
Return values
bool

hasFormatWithModifiers()

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

public static hasFormatWithModifiers(string $date, string $format) : bool
Parameters
$date : string
$format : string
Tags
example
Carbon::hasFormatWithModifiers('31/08/2015', 'd#m#Y'); // true
Carbon::hasFormatWithModifiers('31/08/2015', 'm#d#Y'); // false
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(DateTimeInterface|string $date) : bool
Parameters
$date : DateTimeInterface|string
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(DateTimeInterface|string $date) : bool
Parameters
$date : DateTimeInterface|string
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(DateTimeInterface|string $date1, DateTimeInterface|string $date2[, bool $equal = true ]) : bool
Parameters
$date1 : DateTimeInterface|string
$date2 : DateTimeInterface|string
$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([DateTimeInterface|string|null $date = null ]) : bool
Parameters
$date : DateTimeInterface|string|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|string $dayOfWeek) : bool
Parameters
$dayOfWeek : int|string
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

isEndOfCentury()

Determines if the instance is end of century (last day by default but interval can be customized).

public isEndOfCentury([Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ]) : bool
Parameters
$interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
Return values
bool

isEndOfDay()

Check if the instance is end of day.

public isEndOfDay([bool $checkMicroseconds = false ][, Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ]) : bool
Parameters
$checkMicroseconds : bool = false

check time at microseconds precision

$interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null

if an interval is specified it will be used as precision for instance with "15 minutes", it checks if current date-time is in the last 15 minutes of the day, with Unit::Hour, it checks if it's in the last hour of the day.

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

isEndOfDecade()

Determines if the instance is end of decade (last day by default but interval can be customized).

public isEndOfDecade([Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ]) : bool
Parameters
$interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
Return values
bool

isEndOfHour()

Determines if the instance is end of hour (last microsecond by default but interval can be customized).

public isEndOfHour([Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ]) : bool
Parameters
$interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
Return values
bool

isEndOfMillennium()

Determines if the instance is end of millennium (last day by default but interval can be customized).

public isEndOfMillennium([Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ]) : bool
Parameters
$interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
Return values
bool

isEndOfMillisecond()

Determines if the instance is end of millisecond (last microsecond by default but interval can be customized).

public isEndOfMillisecond([Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ]) : bool
Parameters
$interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
Return values
bool

isEndOfMinute()

Determines if the instance is end of minute (last microsecond by default but interval can be customized).

public isEndOfMinute([Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ]) : bool
Parameters
$interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
Return values
bool

isEndOfMonth()

Determines if the instance is end of month (last day by default but interval can be customized).

public isEndOfMonth([Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ]) : bool
Parameters
$interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
Return values
bool

isEndOfQuarter()

Determines if the instance is end of quarter (last day by default but interval can be customized).

public isEndOfQuarter([Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ]) : bool
Parameters
$interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
Return values
bool

isEndOfSecond()

Determines if the instance is end of second (last microsecond by default but interval can be customized).

public isEndOfSecond([Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ]) : bool
Parameters
$interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
Return values
bool

isEndOfTime()

Returns true if the date was created using CarbonImmutable::endOfTime()

public isEndOfTime() : bool
Return values
bool

isEndOfUnit()

Check if the instance is end of a given unit (tolerating a given interval).

public isEndOfUnit(Unit $unit[, Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ], mixed ...$params) : bool
Parameters
$unit : Unit
$interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
$params : mixed
Tags
example
// Check if a date-time is the last 15 minutes of the hour it's in
Carbon::parse('2019-02-28 20:13:00')->isEndOfUnit(Unit::Hour, '15 minutes'); // false
Return values
bool

isEndOfWeek()

Determines if the instance is end of week (last day by default but interval can be customized).

public isEndOfWeek([Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ][, WeekDay|int|null $weekEndsAt = null ]) : bool
Parameters
$interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
$weekEndsAt : WeekDay|int|null = null
Tags
example
Carbon::parse('2024-08-31')->endOfWeek()->isEndOfWeek(); // true
Carbon::parse('2024-08-31')->isEndOfWeek(); // false
Return values
bool

isEndOfYear()

Determines if the instance is end of year (last day by default but interval can be customized).

public isEndOfYear([Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ]) : bool
Parameters
$interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
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

isLongIsoYear()

Determines if the instance is a long year (using ISO 8601 year).

public isLongIsoYear() : bool
Tags
example
Carbon::parse('2015-01-01')->isLongIsoYear(); // true
Carbon::parse('2016-01-01')->isLongIsoYear(); // true
Carbon::parse('2016-01-03')->isLongIsoYear(); // false
Carbon::parse('2019-12-29')->isLongIsoYear(); // false
Carbon::parse('2019-12-30')->isLongIsoYear(); // true
see
https://en.wikipedia.org/wiki/ISO_8601#Week_dates
Return values
bool

isLongYear()

Determines if the instance is a long year (using calendar year).

public isLongYear() : bool

⚠️ This method completely ignores month and day to use the numeric year number, it's not correct if the exact date matters. For instance as 2019-12-30 is already in the first week of the 2020 year, if you want to know from this date if ISO week year 2020 is a long year, use isLongIsoYear instead.

Tags
example
Carbon::create(2015)->isLongYear(); // true
Carbon::create(2016)->isLongYear(); // false
see
https://en.wikipedia.org/wiki/ISO_8601#Week_dates
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, DateTimeInterface|string $date) : bool
Parameters
$format : string

date formats to compare.

$date : DateTimeInterface|string

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(DateTimeInterface|string $date[, bool $ofSameYear = true ]) : bool
Parameters
$date : DateTimeInterface|string

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(DateTimeInterface|string $date[, bool $ofSameYear = true ]) : bool
Parameters
$date : DateTimeInterface|string

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, DateTimeInterface|string $date) : bool
Parameters
$unit : string

singular unit string

$date : DateTimeInterface|string

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

isStartOfCentury()

Determines if the instance is start of century (first day by default but interval can be customized).

public isStartOfCentury([Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ]) : bool
Parameters
$interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
Return values
bool

isStartOfDay()

Check if the instance is start of day / midnight.

public isStartOfDay([bool $checkMicroseconds = false ][, Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ]) : bool
Parameters
$checkMicroseconds : bool = false

check time at microseconds precision

$interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null

if an interval is specified it will be used as precision for instance with "15 minutes", it checks if current date-time is in the last 15 minutes of the day, with Unit::Hour, it checks if it's in the last hour of the day.

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

isStartOfDecade()

Determines if the instance is start of decade (first day by default but interval can be customized).

public isStartOfDecade([Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ]) : bool
Parameters
$interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
Return values
bool

isStartOfHour()

Determines if the instance is start of hour (first microsecond by default but interval can be customized).

public isStartOfHour([Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ]) : bool
Parameters
$interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
Return values
bool

isStartOfMillennium()

Determines if the instance is start of millennium (first day by default but interval can be customized).

public isStartOfMillennium([Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ]) : bool
Parameters
$interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
Return values
bool

isStartOfMillisecond()

Determines if the instance is start of millisecond (first microsecond by default but interval can be customized).

public isStartOfMillisecond([Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ]) : bool
Parameters
$interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
Return values
bool

isStartOfMinute()

Determines if the instance is start of minute (first microsecond by default but interval can be customized).

public isStartOfMinute([Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ]) : bool
Parameters
$interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
Return values
bool

isStartOfMonth()

Determines if the instance is start of month (first day by default but interval can be customized).

public isStartOfMonth([Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ]) : bool
Parameters
$interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
Return values
bool

isStartOfQuarter()

Determines if the instance is start of quarter (first day by default but interval can be customized).

public isStartOfQuarter([Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ]) : bool
Parameters
$interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
Return values
bool

isStartOfSecond()

Determines if the instance is start of second (first microsecond by default but interval can be customized).

public isStartOfSecond([Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ]) : bool
Parameters
$interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
Return values
bool

isStartOfTime()

Returns true if the date was created using CarbonImmutable::startOfTime()

public isStartOfTime() : bool
Return values
bool

isStartOfUnit()

Check if the instance is start of a given unit (tolerating a given interval).

public isStartOfUnit(Unit $unit[, Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ], mixed ...$params) : bool
Parameters
$unit : Unit
$interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
$params : mixed
Tags
example
// Check if a date-time is the first 15 minutes of the hour it's in
Carbon::parse('2019-02-28 20:13:00')->isStartOfUnit(Unit::Hour, '15 minutes'); // true
Return values
bool

isStartOfWeek()

Determines if the instance is start of week (first day by default but interval can be customized).

public isStartOfWeek([Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ][, WeekDay|int|null $weekStartsAt = null ]) : bool
Parameters
$interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
$weekStartsAt : WeekDay|int|null = null
Tags
example
Carbon::parse('2024-08-31')->startOfWeek()->isStartOfWeek(); // true
Carbon::parse('2024-08-31')->isStartOfWeek(); // false
Return values
bool

isStartOfYear()

Determines if the instance is start of year (first day by default but interval can be customized).

public isStartOfYear([Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ]) : bool
Parameters
$interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
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(DateTimeInterface|string $date) : bool
Parameters
$date : DateTimeInterface|string
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(DateTimeInterface|string $date) : bool
Parameters
$date : DateTimeInterface|string
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(DateTimeInterface|string $date) : bool
Parameters
$date : DateTimeInterface|string
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(DateTimeInterface|string $date) : bool
Parameters
$date : DateTimeInterface|string
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(DateTimeInterface|string $date) : bool
Parameters
$date : DateTimeInterface|string
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(DateTimeInterface|string $date) : bool
Parameters
$date : DateTimeInterface|string
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

nowWithSameTz()

public static nowWithSameTz() : void

resolveCarbon()

public static resolveCarbon(mixed $date) : void
Parameters
$date : mixed

tomorrow()

public static tomorrow(mixed $timezone) : static
Parameters
$timezone : mixed
Return values
static

yesterday()

public static yesterday(mixed $timezone) : static
Parameters
$timezone : mixed
Return values
static

        
On this page

Search results