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
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
Tags
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
Tags
Return values
bool —copy()
public
copy() : CarbonInterface
Return values
CarbonInterface —eq()
Determines if the instance is equal to another
public
eq(Carbon|DateTimeInterface|mixed $date) : bool
Parameters
- $date : Carbon|DateTimeInterface|mixed
Tags
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
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
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
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
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
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
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
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
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
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
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
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
Return values
bool —isDayOfWeek()
Checks if this day is a specific day of the week.
public
isDayOfWeek(int $dayOfWeek) : bool
Parameters
- $dayOfWeek : int
Tags
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
Return values
bool —isFuture()
Determines if the instance is in the future, ie. greater (after) than now.
public
isFuture() : bool
Tags
Return values
bool —isLastOfMonth()
Check if today is the last day of the Month
public
isLastOfMonth() : bool
Tags
Return values
bool —isLeapYear()
Determines if the instance is a leap year.
public
isLeapYear() : bool
Tags
Return values
bool —isLongYear()
Determines if the instance is a long year
public
isLongYear() : bool
Tags
Return values
bool —isMidday()
Check if the instance is midday.
public
isMidday() : bool
Tags
Return values
bool —isMidnight()
Check if the instance is start of day / midnight.
public
isMidnight() : bool
Tags
Return values
bool —isPast()
Determines if the instance is in the past, ie. less (before) than now.
public
isPast() : bool
Tags
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
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
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
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
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
Return values
bool —isToday()
Determines if the instance is today.
public
isToday() : bool
Tags
Return values
bool —isTomorrow()
Determines if the instance is tomorrow.
public
isTomorrow() : bool
Tags
Return values
bool —isWeekday()
Determines if the instance is a weekday.
public
isWeekday() : bool
Tags
Return values
bool —isWeekend()
Determines if the instance is a weekend day.
public
isWeekend() : bool
Tags
Return values
bool —isYesterday()
Determines if the instance is yesterday.
public
isYesterday() : bool
Tags
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
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
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
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
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
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
Return values
bool —nowWithSameTz()
public
nowWithSameTz() : CarbonInterface
Return values
CarbonInterface —resolveCarbon()
public
resolveCarbon(mixed $date) : CarbonInterface
Parameters
- $date : mixed
Return values
CarbonInterface —tomorrow()
public
static tomorrow(mixed $timezone) : CarbonInterface
Parameters
- $timezone : mixed
Return values
CarbonInterface —yesterday()
public
static yesterday(mixed $timezone) : CarbonInterface
Parameters
- $timezone : mixed