Pionia Core

CarbonInterface extends DateTimeInterface, JsonSerializable
in

Common interface for Carbon and CarbonImmutable.

<autodoc generated by composer phpdoc>

Tags
codeCoverageIgnore

Table of Contents

Constants

APRIL  = 4
AUGUST  = 8
CEIL  = 0200
DAYS_PER_WEEK  = 7
DAYS_PER_YEAR  = 365
DECEMBER  = 12
DEFAULT_LOCALE  = 'en'
Default locale (language and region).
DEFAULT_TO_STRING_FORMAT  = 'Y-m-d H:i:s'
Default format to use for __toString method when type juggling occurs.
DIFF_ABSOLUTE  = 1
Diff syntax options.
DIFF_RELATIVE_AUTO  = 0
DIFF_RELATIVE_TO_NOW  = 2
DIFF_RELATIVE_TO_OTHER  = 3
FEBRUARY  = 2
FLOOR  = 0100
FRIDAY  = 5
HOURS_PER_DAY  = 24
ISO_FORMAT_REGEXP  = '(O[YMDHhms]|[Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|YYYYYY|YYYYY|YYYY|YY?|g{1,5}|G{1,5}|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?)'
Pattern detection for ->isoFormat and ::createFromIsoFormat.
JANUARY  = 1
The month constants.
JULY  = 7
JUNE  = 6
JUST_NOW  = 02
MARCH  = 3
MAY  = 5
MICROSECONDS_PER_MILLISECOND  = 1000
MICROSECONDS_PER_SECOND  = 1000000
MILLISECONDS_PER_SECOND  = 1000
MINUTES_PER_HOUR  = 60
MOCK_DATETIME_FORMAT  = 'Y-m-d H:i:s.u'
Format for converting mocked time, includes microseconds.
MONDAY  = 1
MONTHS_PER_QUARTER  = 3
MONTHS_PER_YEAR  = 12
NO_ZERO_DIFF  = 01
Diff wording options(expressed in octal).
NOVEMBER  = 11
OCTOBER  = 10
ONE_DAY_WORDS  = 04
QUARTERS_PER_YEAR  = 4
RFC7231_FORMAT  = 'D, d M Y H:i:s \\G\\M\\T'
RFC7231 DateTime format.
ROUND  = 040
SATURDAY  = 6
SECONDS_PER_MINUTE  = 60
SEPTEMBER  = 9
SEQUENTIAL_PARTS_ONLY  = 020
SUNDAY  = 0
The day constants.
THURSDAY  = 4
TRANSLATE_ALL  = self::TRANSLATE_MONTHS | self::TRANSLATE_DAYS | self::TRANSLATE_UNITS | self::TRANSLATE_MERIDIEM | self::TRANSLATE_DIFF
TRANSLATE_DAYS  = 2
TRANSLATE_DIFF  = 0x10
TRANSLATE_MERIDIEM  = 8
TRANSLATE_MONTHS  = 1
Translate string options.
TRANSLATE_UNITS  = 4
TUESDAY  = 2
TWO_DAY_WORDS  = 010
WEDNESDAY  = 3
WEEK_DAY_AUTO  = 'auto'
Special settings to get the start of week from current locale culture.
WEEKS_PER_MONTH  = 4
WEEKS_PER_YEAR  = 52
YEARS_PER_CENTURY  = 100
YEARS_PER_DECADE  = 10
YEARS_PER_MILLENNIUM  = 1000
Number of X in Y.

Methods

__call()  : mixed
Dynamically handle calls to the class.
__callStatic()  : mixed
Dynamically handle calls to the class.
__clone()  : void
Update constructedObjectId on cloned.
__construct()  : mixed
Create a new Carbon instance.
__debugInfo()  : array<string|int, mixed>
Show truthy properties on var_dump().
__get()  : string|int|bool|DateTimeZone|null
Get a part of the Carbon object.
__isset()  : bool
Check if an attribute exists on the object
__set()  : void
Set a part of the Carbon object
__set_state()  : static
The __set_state handler.
__sleep()  : array<string|int, mixed>
Returns the list of properties to dump on serialize() called on.
__toString()  : mixed
Format the instance as a string using the set format
add()  : static
Add given units or interval to the current instance.
addRealUnit()  : static
addUnit()  : static
Add given units to the current instance.
addUnitNoOverflow()  : static
Add any unit to a new value without overflowing current other unit given.
addUTCUnit()  : static
Add seconds to the instance using timestamp. Positive $value travels forward while negative $value travels into the past.
ago()  : string
Get the difference in a human readable format in the current locale from an other instance given to now
average()  : static
Modify the current instance to the average of a given instance (default now) and the current instance (second-precision).
avoidMutation()  : static
Clone the current instance if it's mutable.
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.
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.
canBeCreatedFromFormat()  : bool
Checks if the (date)time string is in a given format and valid to create a new instance.
carbonize()  : static
Return the Carbon instance passed through, a now instance in the same timezone if null given or parse the input if string given.
cast()  : T
Cast the current instance into the given class.
ceil()  : static
Ceil the current instance second with given precision if specified.
ceilUnit()  : static
Ceil the current instance at the given unit with given precision if specified.
ceilWeek()  : static
Ceil the current instance week.
change()  : static
Similar to native modify() method of DateTime but can handle more grammars.
cleanupDumpProperties()  : mixed
Cleanup properties attached to the public scope of DateTime when a dump of the date is requested.
clone()  : static
closest()  : static
Get the closest date from the instance (second-precision).
copy()  : static
Get a copy of the instance.
create()  : static|null
Create a new Carbon instance from a specific date and time.
createFromDate()  : static
Create a Carbon instance from just a date. The time portion is set to now.
createFromFormat()  : static|null
Create a Carbon instance from a specific format.
createFromIsoFormat()  : static|null
Create a Carbon instance from a specific ISO format (same replacements as ->isoFormat()).
createFromLocaleFormat()  : static|null
Create a Carbon instance from a specific format and a string in a given language.
createFromLocaleIsoFormat()  : static|null
Create a Carbon instance from a specific ISO format and a string in a given language.
createFromTime()  : static
Create a Carbon instance from just a time. The date portion is set to today.
createFromTimestamp()  : static
Create a Carbon instance from a timestamp and set the timezone (UTC by default).
createFromTimestampMs()  : static
Create a Carbon instance from a timestamp in milliseconds.
createFromTimestampMsUTC()  : static
Create a Carbon instance from a timestamp in milliseconds.
createFromTimestampUTC()  : static
Create a Carbon instance from a timestamp keeping the timezone to UTC.
createFromTimeString()  : static
Create a Carbon instance from a time string. The date portion is set to today.
createMidnightDate()  : static
Create a Carbon instance from just a date. The time portion is set to midnight.
createSafe()  : static|null
Create a new safe Carbon instance from a specific date and time.
createStrict()  : static
Create a new Carbon instance from a specific date and time using strict validation.
dayOfYear()  : static|int
Get/set the day of year.
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
disableHumanDiffOption()  : void
enableHumanDiffOption()  : void
endOf()  : static
Modify to end of current given unit.
endOfCentury()  : static
Resets the date to end of the century and time to 23:59:59.999999
endOfDay()  : static
Resets the time to 23:59:59.999999 end of day
endOfDecade()  : static
Resets the date to end of the decade and time to 23:59:59.999999
endOfHour()  : static
Modify to end of current hour, minutes and seconds become 59
endOfMillennium()  : static
Resets the date to end of the millennium and time to 23:59:59.999999
endOfMillisecond()  : static
Modify to end of current millisecond, microseconds such as 12345 become 123999
endOfMinute()  : static
Modify to end of current minute, seconds become 59
endOfMonth()  : static
Resets the date to end of the month and time to 23:59:59.999999
endOfQuarter()  : static
Resets the date to end of the quarter and time to 23:59:59.999999
endOfSecond()  : static
Modify to end of current second, microseconds become 999999
endOfWeek()  : static
Resets the date to end of week (defined in $weekEndsAt) and time to 23:59:59.999999
endOfYear()  : static
Resets the date to end of the year and time to 23:59:59.999999
eq()  : bool
Determines if the instance is equal to another
equalTo()  : bool
Determines if the instance is equal to another
executeWithLocale()  : mixed
Set the current locale to the given, execute the passed function, reset the locale to previous one, then return the result of the closure (or null if the closure was void).
farthest()  : static
Get the farthest date from the instance (second-precision).
firstOfMonth()  : static
Modify to the first occurrence of a given day of the week in the current month. If no dayOfWeek is provided, modify to the first day of the current month. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
firstOfQuarter()  : static
Modify to the first occurrence of a given day of the week in the current quarter. If no dayOfWeek is provided, modify to the first day of the current quarter. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
firstOfYear()  : static
Modify to the first occurrence of a given day of the week in the current year. If no dayOfWeek is provided, modify to the first day of the current year. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
floor()  : static
Round the current instance second with given precision if specified.
floorUnit()  : static
Truncate the current instance at the given unit with given precision if specified.
floorWeek()  : static
Truncate the current instance week.
from()  : string
fromNow()  : string
Get the difference in a human readable format in the current locale from current instance to now.
fromSerialized()  : static
Create an instance from a serialized string.
genericMacro()  : void
Register a custom macro.
get()  : string|int|bool|DateTimeZone
Get a part of the Carbon object.
getAltNumber()  : string
Returns the alternative number for a given date property if available in the current locale.
getAvailableLocales()  : array<string|int, mixed>
Returns the list of internally available locales and already loaded custom locales.
getAvailableLocalesInfo()  : array<string|int, Language>
Returns list of Language object for each available locale. This object allow you to get the ISO name, native name, region and variant of the locale.
getCalendarFormats()  : array<string|int, mixed>
Returns list of calendar formats for ISO formatting.
getClock()  : WrapperClock|null
getDays()  : array<string|int, mixed>
Get the days of the week.
getDaysFromStartOfWeek()  : int
Return the number of days since the start of the week (using the current locale or the first parameter if explicitly given).
getFallbackLocale()  : string|null
Get the fallback locale.
getFormatsToIsoReplacements()  : array<string|int, mixed>
List of replacements from date() format to isoFormat().
getHumanDiffOptions()  : int
Return default humanDiff() options (merged flags as integer).
getIsoFormats()  : array<string|int, mixed>
Returns list of locale formats for ISO formatting.
getIsoUnits()  : array<string|int, mixed>
Returns list of locale units for ISO formatting.
getLastErrors()  : array<string|int, mixed>|false
{@inheritdoc}
getLocale()  : string
Get the current translator locale.
getLocalMacro()  : callable|null
Get the raw callable macro registered globally or locally for a given name.
getLocalTranslator()  : TranslatorInterface
Get the translator of the current instance or the default if none set.
getMacro()  : callable|null
Get the raw callable macro registered globally for a given name.
getMidDayAt()  : int
get midday/noon hour
getOffsetString()  : string
Returns the offset hour and minute formatted with +/- and a given separator (":" by default).
getPaddedUnit()  : string
Returns a unit of the instance padded with 0 by default or any other string if specified.
getPreciseTimestamp()  : float
Returns a timestamp rounded with the given precision (6 by default).
getSettings()  : array<string|int, mixed>
Returns current local settings.
getTestNow()  : Closure|self|null
Get the Carbon instance (real or mock) to be returned when a "now" instance is created.
getTimeFormatByPrecision()  : string
Return a format from H:i to H:i:s.u according to given unit precision.
getTimestampMs()  : int
Returns the timestamp with millisecond precision.
getTranslatedDayName()  : string
Get the translation of the current week day name (with context for languages with multiple forms).
getTranslatedMinDayName()  : string
Get the translation of the current abbreviated week day name (with context for languages with multiple forms).
getTranslatedMonthName()  : string
Get the translation of the current month day name (with context for languages with multiple forms).
getTranslatedShortDayName()  : string
Get the translation of the current short week day name (with context for languages with multiple forms).
getTranslatedShortMonthName()  : string
Get the translation of the current short month day name (with context for languages with multiple forms).
getTranslationMessage()  : string
Returns raw translation message for a given key.
getTranslationMessageWith()  : string|Closure|null
Returns raw translation message for a given key.
getTranslator()  : TranslatorInterface
Initialize the default translator instance if necessary.
getWeekendDays()  : array<string|int, mixed>
Get weekend days
getWeekEndsAt()  : int
Get the last day of week.
getWeekStartsAt()  : int
Get the first day of week.
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.
hasLocalMacro()  : bool
Checks if macro is registered globally or locally.
hasLocalTranslator()  : bool
Return true if the current instance has its own translator.
hasMacro()  : bool
Checks if macro is registered globally.
hasRelativeKeywords()  : bool
Determine if a time string will produce a relative date.
hasTestNow()  : bool
Determine if there is a valid test instance set. A valid test instance is anything that is not null.
instance()  : static
Create a Carbon instance from a DateTime one.
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.
isImmutable()  : bool
Returns true if the current class/instance is immutable.
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.
isModifiableUnit()  : bool
Returns true if a property can be changed via setter.
isMutable()  : bool
Returns true if the current class/instance is mutable.
isoFormat()  : string
Format in the current language using ISO replacement patterns.
isoWeek()  : int|static
Get/set the week number using given first day of week and first day of year included in the first week. Or use ISO format if no settings given.
isoWeekday()  : static|int
Get/set the ISO weekday from 1 (Monday) to 7 (Sunday).
isoWeeksInYear()  : int
Get the number of weeks of the current week-year using given first day of week and first day of year included in the first week. Or use ISO format if no settings given.
isoWeekYear()  : int|static
Set/get the week number of year using given first day of week and first day of year included in the first week. Or use ISO format if no settings given.
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).
isStrictModeEnabled()  : bool
Returns true if the strict mode is globally in use, false else.
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.
jsonSerialize()  : mixed
Prepare the object for JSON serialization.
lastOfMonth()  : static
Modify to the last occurrence of a given day of the week in the current month. If no dayOfWeek is provided, modify to the last day of the current month. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
lastOfQuarter()  : static
Modify to the last occurrence of a given day of the week in the current quarter. If no dayOfWeek is provided, modify to the last day of the current quarter. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
lastOfYear()  : static
Modify to the last occurrence of a given day of the week in the current year. If no dayOfWeek is provided, modify to the last day of the current year. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
lessThan()  : bool
Determines if the instance is less (before) than another
lessThanOrEqualTo()  : bool
Determines if the instance is less (before) or equal to another
locale()  : $this|string
Get/set the locale for the current instance.
localeHasDiffOneDayWords()  : bool
Returns true if the given locale is internally supported and has words for 1-day diff (just now, yesterday, tomorrow).
localeHasDiffSyntax()  : bool
Returns true if the given locale is internally supported and has diff syntax support (ago, from now, before, after).
localeHasDiffTwoDayWords()  : bool
Returns true if the given locale is internally supported and has words for 2-days diff (before yesterday, after tomorrow).
localeHasPeriodSyntax()  : bool
Returns true if the given locale is internally supported and has period syntax support (X times, every X, from X, to X).
localeHasShortUnits()  : bool
Returns true if the given locale is internally supported and has short-units support.
lt()  : bool
Determines if the instance is less (before) than another
lte()  : bool
Determines if the instance is less (before) or equal to another
macro()  : void
Register a custom macro.
make()  : static|null
Make a Carbon instance from given variable if possible.
max()  : static
Get the maximum instance between a given instance (default now) and the current instance.
maximum()  : static
Get the maximum instance between a given instance (default now) and the current instance.
meridiem()  : string
Return the meridiem of the current time in the current locale.
midDay()  : static
Modify to midday, default to self::$midDayAt
min()  : static
Get the minimum instance between a given instance (default now) and the current instance.
minimum()  : static
Get the minimum instance between a given instance (default now) and the current instance.
mixin()  : void
Mix another object into the class.
modify()  : static
Calls \DateTime::modify if mutable or \DateTimeImmutable::modify else.
ne()  : bool
Determines if the instance is not equal to another
next()  : static
Modify to the next occurrence of a given modifier such as a day of the week. If no modifier is provided, modify to the next occurrence of the current day of the week. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
nextWeekday()  : static
Go forward to the next weekday.
nextWeekendDay()  : static
Go forward to the next weekend day.
notEqualTo()  : bool
Determines if the instance is not equal to another
now()  : static
Get a Carbon instance for the current date and time.
nowWithSameTz()  : static
Returns a present instance in the same timezone.
nthOfMonth()  : mixed
Modify to the given occurrence of a given day of the week in the current month. If the calculated occurrence is outside the scope of the current month, then return false and no modifications are made.
nthOfQuarter()  : mixed
Modify to the given occurrence of a given day of the week in the current quarter. If the calculated occurrence is outside the scope of the current quarter, then return false and no modifications are made.
nthOfYear()  : mixed
Modify to the given occurrence of a given day of the week in the current year. If the calculated occurrence is outside the scope of the current year, then return false and no modifications are made.
ordinal()  : string
Return a property with its ordinal.
parse()  : static
Create a carbon instance from a string.
parseFromLocale()  : static
Create a carbon instance from a localized string (in French, Japanese, Arabic, etc.).
pluralUnit()  : string
Returns standardized plural of a given singular/plural unit name (in English).
previous()  : static
Modify to the previous occurrence of a given modifier such as a day of the week. If no dayOfWeek is provided, modify to the previous occurrence of the current day of the week. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
previousWeekday()  : static
Go backward to the previous weekday.
previousWeekendDay()  : static
Go backward to the previous weekend day.
range()  : CarbonPeriod
Create a iterable CarbonPeriod object from current date to a given end date (and optional interval).
rawAdd()  : static
Call native PHP DateTime/DateTimeImmutable add() method.
rawCreateFromFormat()  : static|null
Create a Carbon instance from a specific format.
rawFormat()  : string
rawParse()  : static
Create a carbon instance from a string.
rawSub()  : static
Call native PHP DateTime/DateTimeImmutable sub() method.
resetMacros()  : void
Remove all macros and generic macros.
resetMonthsOverflow()  : void
resetToStringFormat()  : void
Reset the format used to the default when type juggling a Carbon instance to a string
resetYearsOverflow()  : void
round()  : static
Round the current instance second with given precision if specified.
roundUnit()  : static
Round the current instance at the given unit with given precision if specified and the given function.
roundWeek()  : static
Round the current instance week.
secondsSinceMidnight()  : float
The number of seconds since midnight.
secondsUntilEndOfDay()  : float
The number of seconds until 23:59:59.
serialize()  : string
Return a serialized string of the instance.
serializeUsing()  : void
set()  : $this
Set a part of the Carbon object.
setDate()  : static
Set the date with gregorian year, month and day numbers.
setDateFrom()  : static
Set the year, month, and date for this instance to that of the passed instance.
setDateTime()  : static
Set the date and time all together.
setDateTimeFrom()  : static
Set the date and time for this instance to that of the passed instance.
setDaysFromStartOfWeek()  : static
Set the day (keeping the current time) to the start of the week + the number of days passed as the first parameter. First day of week is driven by the locale unless explicitly set with the second parameter.
setFallbackLocale()  : void
Set the fallback locale.
setHumanDiffOptions()  : void
setISODate()  : static
Set a date according to the ISO 8601 standard - using weeks and day offsets rather than specific dates.
setLocale()  : void
Set the current translator locale and indicate if the source locale file exists.
setLocalTranslator()  : mixed
Set the translator for the current instance.
setMidDayAt()  : void
setTestNow()  : void
Set a Carbon instance (real or mock) to be returned when a "now" instance is created. The provided instance will be returned specifically under the following conditions: - A call to the static now() method, ex. Carbon::now() - When a null (or blank string) is passed to the constructor or parse(), ex. new Carbon(null) - When the string "now" is passed to the constructor or parse(), ex. new Carbon('now') - When a string containing the desired time is passed to Carbon::parse().
setTestNowAndTimezone()  : void
Set a Carbon instance (real or mock) to be returned when a "now" instance is created. The provided instance will be returned specifically under the following conditions: - A call to the static now() method, ex. Carbon::now() - When a null (or blank string) is passed to the constructor or parse(), ex. new Carbon(null) - When the string "now" is passed to the constructor or parse(), ex. new Carbon('now') - When a string containing the desired time is passed to Carbon::parse().
setTime()  : static
Resets the current time of the DateTime object to a different time.
setTimeFrom()  : static
Set the hour, minute, second and microseconds for this instance to that of the passed instance.
setTimeFromTimeString()  : static
Set the time by time string.
setTimestamp()  : static
Set the instance's timestamp.
setTimezone()  : static
Set the instance's timezone from a string or object.
settings()  : $this|static
Set specific options.
setToStringFormat()  : void
setTranslator()  : void
Set the default translator instance to use.
setUnit()  : static
Set specified unit to new given value.
setUnitNoOverflow()  : static
Set any unit to a new value without overflowing current other unit given.
setWeekendDays()  : void
shiftTimezone()  : static
Set the instance's timezone from a string or object and add/subtract the offset difference.
shouldOverflowMonths()  : bool
Get the month overflow global behavior (can be overridden in specific instances).
shouldOverflowYears()  : bool
Get the month overflow global behavior (can be overridden in specific instances).
since()  : mixed
singularUnit()  : string
Returns standardized singular of a given singular/plural unit name (in English).
sleep()  : void
startOf()  : static
Modify to start of current given unit.
startOfCentury()  : static
Resets the date to the first day of the century and the time to 00:00:00
startOfDay()  : static
Resets the time to 00:00:00 start of day
startOfDecade()  : static
Resets the date to the first day of the decade and the time to 00:00:00
startOfHour()  : static
Modify to start of current hour, minutes and seconds become 0
startOfMillennium()  : static
Resets the date to the first day of the millennium and the time to 00:00:00
startOfMillisecond()  : static
Modify to start of current millisecond, microseconds such as 12345 become 123000
startOfMinute()  : static
Modify to start of current minute, seconds become 0
startOfMonth()  : static
Resets the date to the first day of the month and the time to 00:00:00
startOfQuarter()  : static
Resets the date to the first day of the quarter and the time to 00:00:00
startOfSecond()  : static
Modify to start of current second, microseconds become 0
startOfWeek()  : static
Resets the date to the first day of week (defined in $weekStartsAt) and the time to 00:00:00
startOfYear()  : static
Resets the date to the first day of the year and the time to 00:00:00
sub()  : static
Subtract given units or interval to the current instance.
subRealUnit()  : static
subtract()  : static
Subtract given units or interval to the current instance.
subUnit()  : static
Subtract given units to the current instance.
subUnitNoOverflow()  : static
Subtract any unit to a new value without overflowing current other unit given.
subUTCUnit()  : static
Subtract seconds to the instance using timestamp. Positive $value travels into the past while negative $value travels forward.
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).
timestamp()  : static
Set the instance's timestamp.
timezone()  : static
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.
toArray()  : array<string|int, mixed>
Get default array representation.
toAtomString()  : string
Format the instance as ATOM
toCookieString()  : string
Format the instance as COOKIE
toDate()  : DateTime
toDateString()  : string
Format the instance as date
toDateTime()  : DateTime
Return native DateTime PHP object matching the current instance.
toDateTimeImmutable()  : DateTimeImmutable
Return native toDateTimeImmutable PHP object matching the current instance.
toDateTimeLocalString()  : string
Format the instance as date and time T-separated with no timezone
toDateTimeString()  : string
Format the instance as date and time
today()  : static
Create a Carbon instance for today.
toDayDateTimeString()  : string
Format the instance with day, date and time
toFormattedDateString()  : string
Format the instance as a readable date
toFormattedDayDateString()  : string
Format the instance with the day, and a readable date
toImmutable()  : CarbonImmutable
Return a immutable copy of the instance.
toIso8601String()  : string
Format the instance as ISO8601
toIso8601ZuluString()  : string
Convert the instance to UTC and return as Zulu ISO8601
toISOString()  : string|null
Return the ISO-8601 string (ex: 1977-04-22T06:00:00Z, if $keepOffset truthy, offset will be kept: 1977-04-22T01:00:00-05:00).
toJSON()  : string|null
Return the ISO-8601 string (ex: 1977-04-22T06:00:00Z) with UTC timezone.
tomorrow()  : static
Create a Carbon instance for tomorrow.
toMutable()  : Carbon
Return a mutable copy of the instance.
toNow()  : string
Get the difference in a human readable format in the current locale from an other instance given to now
toObject()  : object
Get default object representation.
toPeriod()  : CarbonPeriod
Create a iterable CarbonPeriod object from current date to a given end date (and optional interval).
toRfc1036String()  : string
Format the instance as RFC1036
toRfc1123String()  : string
Format the instance as RFC1123
toRfc2822String()  : string
Format the instance as RFC2822
toRfc3339String()  : string
Format the instance as RFC3339.
toRfc7231String()  : string
Format the instance as RFC7231
toRfc822String()  : string
Format the instance as RFC822
toRfc850String()  : string
Format the instance as RFC850
toRssString()  : string
Format the instance as RSS
toString()  : string
Returns english human-readable complete date string.
toTimeString()  : string
Format the instance as time
toW3cString()  : string
Format the instance as W3C
translate()  : string
Translate using translation string or callback available.
translatedFormat()  : string
Format as ->format() do (using date replacements patterns from https://php.net/manual/en/function.date.php) but translate words whenever possible (months, day names, etc.) using the current locale.
translateNumber()  : string
Returns the alternative number for a given integer if available in the current locale.
translateTimeString()  : string
Translate a time string from a locale to an other.
translateTimeStringTo()  : string
Translate a time string from the current locale (`$date->locale()`) to an other.
translateWith()  : string
Translate using translation string or callback available.
tz()  : static|string
Set the timezone or returns the timezone name if no arguments passed.
unix()  : int
until()  : string
useMonthsOverflow()  : void
useStrictMode()  : void
useYearsOverflow()  : void
utc()  : static
Set the instance's timezone to UTC.
utcOffset()  : static|int
Returns the minutes offset to UTC if no arguments passed, else set the timezone with given minutes shift passed.
valueOf()  : float
Returns the milliseconds timestamps used amongst other by Date javascript objects.
week()  : int|static
Get/set the week number using given first day of week and first day of year included in the first week. Or use US format if no settings given (Sunday / Jan 6).
weekday()  : static|int
Get/set the weekday from 0 (Sunday) to 6 (Saturday).
weeksInYear()  : int
Get the number of weeks of the current week-year using given first day of week and first day of year included in the first week. Or use US format if no settings given (Sunday / Jan 6).
weekYear()  : int|static
Set/get the week number of year using given first day of week and first day of year included in the first week. Or use US format if no settings given (Sunday / Jan 6).
withTestNow()  : T
Temporarily sets a static date to be used within the callback.
yesterday()  : static
Create a Carbon instance for yesterday.

Constants

DEFAULT_LOCALE

Default locale (language and region).

public string DEFAULT_LOCALE = 'en'

DEFAULT_TO_STRING_FORMAT

Default format to use for __toString method when type juggling occurs.

public string DEFAULT_TO_STRING_FORMAT = 'Y-m-d H:i:s'

ISO_FORMAT_REGEXP

Pattern detection for ->isoFormat and ::createFromIsoFormat.

public string ISO_FORMAT_REGEXP = '(O[YMDHhms]|[Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|YYYYYY|YYYYY|YYYY|YY?|g{1,5}|G{1,5}|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?)'

JANUARY

The month constants.

public mixed JANUARY = 1

These aren't used by Carbon itself but exist for convenience sake alone.

MICROSECONDS_PER_MILLISECOND

public mixed MICROSECONDS_PER_MILLISECOND = 1000

MICROSECONDS_PER_SECOND

public mixed MICROSECONDS_PER_SECOND = 1000000

MILLISECONDS_PER_SECOND

public mixed MILLISECONDS_PER_SECOND = 1000

MOCK_DATETIME_FORMAT

Format for converting mocked time, includes microseconds.

public string MOCK_DATETIME_FORMAT = 'Y-m-d H:i:s.u'

NO_ZERO_DIFF

Diff wording options(expressed in octal).

public mixed NO_ZERO_DIFF = 01

RFC7231_FORMAT

RFC7231 DateTime format.

public string RFC7231_FORMAT = 'D, d M Y H:i:s \\G\\M\\T'

TRANSLATE_ALL

public mixed TRANSLATE_ALL = self::TRANSLATE_MONTHS | self::TRANSLATE_DAYS | self::TRANSLATE_UNITS | self::TRANSLATE_MERIDIEM | self::TRANSLATE_DIFF

TRANSLATE_MONTHS

Translate string options.

public mixed TRANSLATE_MONTHS = 1

WEEK_DAY_AUTO

Special settings to get the start of week from current locale culture.

public mixed WEEK_DAY_AUTO = 'auto'

YEARS_PER_MILLENNIUM

Number of X in Y.

public mixed YEARS_PER_MILLENNIUM = 1000

Methods

__call()

Dynamically handle calls to the class.

public __call(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
$method : string

magic method name called

$parameters : array<string|int, mixed>

parameters list

Tags
throws
UnknownMethodException|BadMethodCallException|ReflectionException|Throwable

__callStatic()

Dynamically handle calls to the class.

public static __callStatic(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
$method : string

magic method name called

$parameters : array<string|int, mixed>

parameters list

Tags
throws
BadMethodCallException

__clone()

Update constructedObjectId on cloned.

public __clone() : void

__construct()

Create a new Carbon instance.

public __construct([DateTimeInterface|WeekDay|Month|string|int|float|null $time = null ][, DateTimeZone|string|int|null $timezone = null ]) : mixed

Please see the testing aids section (specifically static::setTestNow()) for more on the possibility of this constructor returning a test instance.

Parameters
$time : DateTimeInterface|WeekDay|Month|string|int|float|null = null
$timezone : DateTimeZone|string|int|null = null
Tags
throws
InvalidFormatException

__debugInfo()

Show truthy properties on var_dump().

public __debugInfo() : array<string|int, mixed>
Return values
array<string|int, mixed>

__get()

Get a part of the Carbon object.

public __get(string $name) : string|int|bool|DateTimeZone|null
Parameters
$name : string
Tags
throws
UnknownGetterException
Return values
string|int|bool|DateTimeZone|null

__isset()

Check if an attribute exists on the object

public __isset(string $name) : bool
Parameters
$name : string
Return values
bool

__set()

Set a part of the Carbon object

public __set(string $name, string|int|DateTimeZone $value) : void
Parameters
$name : string
$value : string|int|DateTimeZone
Tags
throws
UnknownSetterException|ReflectionException

__set_state()

The __set_state handler.

public static __set_state(string|array<string|int, mixed> $dump) : static
Parameters
$dump : string|array<string|int, mixed>
Return values
static

__sleep()

Returns the list of properties to dump on serialize() called on.

public __sleep() : array<string|int, mixed>

Only used by PHP < 7.4.

Return values
array<string|int, mixed>

__toString()

Format the instance as a string using the set format

public __toString() : mixed
Tags
example
echo Carbon::now(); // Carbon instances can be cast to string

add()

Add given units or interval to the current instance.

public add(Unit|string|DateInterval|Closure|CarbonConverterInterface $unit[, int|float $value = 1 ][, bool|null $overflow = null ]) : static
Parameters
$unit : Unit|string|DateInterval|Closure|CarbonConverterInterface
$value : int|float = 1
$overflow : bool|null = null
Tags
example

$date->add('hour', 3)

example

$date->add(15, 'days')

example

$date->add(CarbonInterval::days(4))

Return values
static

addRealUnit()

public addRealUnit(string $unit[, int|float|null $value = 1 ]) : static
Parameters
$unit : string
$value : int|float|null = 1
Tags
deprecated

Prefer to use add addUTCUnit() which more accurately defines what it's doing.

Add seconds to the instance using timestamp. Positive $value travels forward while negative $value travels into the past.

Return values
static

addUnit()

Add given units to the current instance.

public addUnit(Unit|string $unit[, mixed $value = 1 ][, bool|null $overflow = null ]) : static
Parameters
$unit : Unit|string
$value : mixed = 1
$overflow : bool|null = null
Return values
static

addUnitNoOverflow()

Add any unit to a new value without overflowing current other unit given.

public addUnitNoOverflow(string $valueUnit, int $value, string $overflowUnit) : static
Parameters
$valueUnit : string

unit name to modify

$value : int

amount to add to the input unit

$overflowUnit : string

unit name to not overflow

Return values
static

addUTCUnit()

Add seconds to the instance using timestamp. Positive $value travels forward while negative $value travels into the past.

public addUTCUnit(string $unit[, int|float|null $value = 1 ]) : static
Parameters
$unit : string
$value : int|float|null = 1
Return values
static

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
string

average()

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

public average([Carbon|DateTimeInterface|null $date = null ]) : static
Parameters
$date : Carbon|DateTimeInterface|null = null
Return values
static

avoidMutation()

Clone the current instance if it's mutable.

public avoidMutation() : static

This method is convenient to ensure you don't mutate the initial object but avoid to make a useless copy of it if it's already immutable.

Return values
static

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

calendar()

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
string

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

carbonize()

Return the Carbon instance passed through, a now instance in the same timezone if null given or parse the input if string given.

public carbonize([Carbon|CarbonPeriod|CarbonInterval|DateInterval|DatePeriod|DateTimeInterface|string|null $date = null ]) : static
Parameters
$date : Carbon|CarbonPeriod|CarbonInterval|DateInterval|DatePeriod|DateTimeInterface|string|null = null
Return values
static

cast()

Cast the current instance into the given class.

public cast(T> $className) : T
Parameters
$className : T>

The $className::instance() method will be called to cast the current object.

Tags
template

T

Return values
T

ceil()

Ceil the current instance second with given precision if specified.

public ceil([DateInterval|string|int|float $precision = 1 ]) : static
Parameters
$precision : DateInterval|string|int|float = 1
Return values
static

ceilUnit()

Ceil the current instance at the given unit with given precision if specified.

public ceilUnit(string $unit[, DateInterval|string|int|float $precision = 1 ]) : static
Parameters
$unit : string
$precision : DateInterval|string|int|float = 1
Return values
static

ceilWeek()

Ceil the current instance week.

public ceilWeek([WeekDay|int|null $weekStartsAt = null ]) : static
Parameters
$weekStartsAt : WeekDay|int|null = null

optional start allow you to specify the day of week to use to start the week

Return values
static

cleanupDumpProperties()

Cleanup properties attached to the public scope of DateTime when a dump of the date is requested.

public cleanupDumpProperties() : mixed

foreach ($date as $_) } serializer($date) var_export($date) get_object_vars($date)

clone()

public clone() : static
Tags
alias

copy

Get a copy of the instance.

Return values
static

closest()

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

public closest(Carbon|DateTimeInterface|mixed $date1, Carbon|DateTimeInterface|mixed $date2) : static
Parameters
$date1 : Carbon|DateTimeInterface|mixed
$date2 : Carbon|DateTimeInterface|mixed
Return values
static

copy()

Get a copy of the instance.

public copy() : static
Return values
static

create()

Create a new Carbon instance from a specific date and time.

public static create([DateTimeInterface|string|int|null $year = 0 ][, int|null $month = 1 ][, int|null $day = 1 ][, int|null $hour = 0 ][, int|null $minute = 0 ][, int|null $second = 0 ][, DateTimeZone|string|int|null $timezone = null ]) : static|null

If any of $year, $month or $day are set to null their now() values will be used.

If $hour is null it will be set to its now() value and the default values for $minute and $second will be their now() values.

If $hour is not null then the default values for $minute and $second will be 0.

Parameters
$year : DateTimeInterface|string|int|null = 0
$month : int|null = 1
$day : int|null = 1
$hour : int|null = 0
$minute : int|null = 0
$second : int|null = 0
$timezone : DateTimeZone|string|int|null = null
Tags
throws
InvalidFormatException
Return values
static|null

createFromDate()

Create a Carbon instance from just a date. The time portion is set to now.

public static createFromDate([int|null $year = null ][, int|null $month = null ][, int|null $day = null ][, DateTimeZone|string|int|null $timezone = null ]) : static
Parameters
$year : int|null = null
$month : int|null = null
$day : int|null = null
$timezone : DateTimeZone|string|int|null = null
Tags
throws
InvalidFormatException
Return values
static

createFromFormat()

Create a Carbon instance from a specific format.

public static createFromFormat(string $format, string $time[, DateTimeZone|string|int|null $timezone = null ]) : static|null
Parameters
$format : string

Datetime format

$time : string
$timezone : DateTimeZone|string|int|null = null
Tags
throws
InvalidFormatException
Return values
static|null

createFromIsoFormat()

Create a Carbon instance from a specific ISO format (same replacements as ->isoFormat()).

public static createFromIsoFormat(string $format, string $time[, DateTimeZone|string|int|null $timezone = null ][, string|null $locale = 'en' ][, TranslatorInterface|null $translator = null ]) : static|null
Parameters
$format : string

Datetime format

$time : string
$timezone : DateTimeZone|string|int|null = null

optional timezone

$locale : string|null = 'en'

locale to be used for LTS, LT, LL, LLL, etc. macro-formats (en by fault, unneeded if no such macro-format in use)

$translator : TranslatorInterface|null = null

optional custom translator to use for macro-formats

Tags
throws
InvalidFormatException
Return values
static|null

createFromLocaleFormat()

Create a Carbon instance from a specific format and a string in a given language.

public static createFromLocaleFormat(string $format, string $locale, string $time[, DateTimeZone|string|int|null $timezone = null ]) : static|null
Parameters
$format : string

Datetime format

$locale : string
$time : string
$timezone : DateTimeZone|string|int|null = null
Tags
throws
InvalidFormatException
Return values
static|null

createFromLocaleIsoFormat()

Create a Carbon instance from a specific ISO format and a string in a given language.

public static createFromLocaleIsoFormat(string $format, string $locale, string $time[, DateTimeZone|string|int|null $timezone = null ]) : static|null
Parameters
$format : string

Datetime ISO format

$locale : string
$time : string
$timezone : DateTimeZone|string|int|null = null
Tags
throws
InvalidFormatException
Return values
static|null

createFromTime()

Create a Carbon instance from just a time. The date portion is set to today.

public static createFromTime([int|null $hour = 0 ][, int|null $minute = 0 ][, int|null $second = 0 ][, DateTimeZone|string|int|null $timezone = null ]) : static
Parameters
$hour : int|null = 0
$minute : int|null = 0
$second : int|null = 0
$timezone : DateTimeZone|string|int|null = null
Tags
throws
InvalidFormatException
Return values
static

createFromTimestamp()

Create a Carbon instance from a timestamp and set the timezone (UTC by default).

public static createFromTimestamp(string|int|float $timestamp[, DateTimeZone|string|int|null $timezone = null ]) : static

Timestamp input can be given as int, float or a string containing one or more numbers.

Parameters
$timestamp : string|int|float
$timezone : DateTimeZone|string|int|null = null
Return values
static

createFromTimestampMs()

Create a Carbon instance from a timestamp in milliseconds.

public static createFromTimestampMs(string|int|float $timestamp[, DateTimeZone|string|int|null $timezone = null ]) : static

Timestamp input can be given as int, float or a string containing one or more numbers.

Parameters
$timestamp : string|int|float
$timezone : DateTimeZone|string|int|null = null
Return values
static

createFromTimestampMsUTC()

Create a Carbon instance from a timestamp in milliseconds.

public static createFromTimestampMsUTC(float|int|string $timestamp) : static

Timestamp input can be given as int, float or a string containing one or more numbers.

Parameters
$timestamp : float|int|string
Return values
static

createFromTimestampUTC()

Create a Carbon instance from a timestamp keeping the timezone to UTC.

public static createFromTimestampUTC(string|int|float $timestamp) : static

Timestamp input can be given as int, float or a string containing one or more numbers.

Parameters
$timestamp : string|int|float
Return values
static

createFromTimeString()

Create a Carbon instance from a time string. The date portion is set to today.

public static createFromTimeString(string $time[, DateTimeZone|string|int|null $timezone = null ]) : static
Parameters
$time : string
$timezone : DateTimeZone|string|int|null = null
Tags
throws
InvalidFormatException
Return values
static

createMidnightDate()

Create a Carbon instance from just a date. The time portion is set to midnight.

public static createMidnightDate([int|null $year = null ][, int|null $month = null ][, int|null $day = null ][, DateTimeZone|string|int|null $timezone = null ]) : static
Parameters
$year : int|null = null
$month : int|null = null
$day : int|null = null
$timezone : DateTimeZone|string|int|null = null
Tags
throws
InvalidFormatException
Return values
static

createSafe()

Create a new safe Carbon instance from a specific date and time.

public static createSafe([int|null $year = null ][, int|null $month = null ][, int|null $day = null ][, int|null $hour = null ][, int|null $minute = null ][, int|null $second = null ][, DateTimeZone|string|int|null $timezone = null ]) : static|null

If any of $year, $month or $day are set to null their now() values will be used.

If $hour is null it will be set to its now() value and the default values for $minute and $second will be their now() values.

If $hour is not null then the default values for $minute and $second will be 0.

If one of the set values is not valid, an InvalidDateException will be thrown.

Parameters
$year : int|null = null
$month : int|null = null
$day : int|null = null
$hour : int|null = null
$minute : int|null = null
$second : int|null = null
$timezone : DateTimeZone|string|int|null = null
Tags
throws
InvalidDateException
Return values
static|null

createStrict()

Create a new Carbon instance from a specific date and time using strict validation.

public static createStrict([int|null $year = 0 ][, int|null $month = 1 ][, int|null $day = 1 ][, int|null $hour = 0 ][, int|null $minute = 0 ][, int|null $second = 0 ][, DateTimeZone|string|int|null $timezone = null ]) : static
Parameters
$year : int|null = 0
$month : int|null = 1
$day : int|null = 1
$hour : int|null = 0
$minute : int|null = 0
$second : int|null = 0
$timezone : DateTimeZone|string|int|null = null
Tags
see
create()
throws
InvalidFormatException
Return values
static

dayOfYear()

Get/set the day of year.

public dayOfYear([int|null $value = null ]) : static|int
Parameters
$value : int|null = null

new value for day of year if using as setter.

Tags
template

T of int|null

psalm-param

T $value

psalm-return

(T is int ? static : int)

Return values
static|int

diffAsCarbonInterval()

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
CarbonInterval

diffAsDateInterval()

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
DateInterval

diffFiltered()

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
int

diffForHumans()

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
example
echo Carbon::tomorrow()->diffForHumans() . "\n";
echo Carbon::tomorrow()->diffForHumans(['parts' => 2]) . "\n";
echo Carbon::tomorrow()->diffForHumans(['parts' => 3, 'join' => true]) . "\n";
echo Carbon::tomorrow()->diffForHumans(Carbon::yesterday()) . "\n";
echo Carbon::tomorrow()->diffForHumans(Carbon::yesterday(), ['short' => true]) . "\n";
Return values
string

diffInDays()

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
float

diffInDaysFiltered()

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
int

diffInHours()

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
float

diffInHoursFiltered()

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
int

diffInMicroseconds()

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
float

diffInMilliseconds()

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
float

diffInMinutes()

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
float

diffInMonths()

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
float

diffInQuarters()

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
float

diffInSeconds()

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
float

diffInUnit()

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
float

diffInWeekdays()

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
int

diffInWeekendDays()

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
int

diffInWeeks()

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
float

diffInYears()

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
float

disableHumanDiffOption()

public static disableHumanDiffOption(int $humanDiffOption) : void
Parameters
$humanDiffOption : int
Tags
deprecated

To avoid conflict between different third-party libraries, static setters should not be used. You should rather use the ->settings() method.

see
settings

enableHumanDiffOption()

public static enableHumanDiffOption(int $humanDiffOption) : void
Parameters
$humanDiffOption : int
Tags
deprecated

To avoid conflict between different third-party libraries, static setters should not be used. You should rather use the ->settings() method.

see
settings

endOf()

Modify to end of current given unit.

public endOf(Unit|string $unit, mixed ...$params) : static
Parameters
$unit : Unit|string
$params : mixed
Tags
example
echo Carbon::parse('2018-07-25 12:45:16.334455')
  ->startOf(Unit::Month)
  ->endOf(Unit::Week, Carbon::FRIDAY);
Return values
static

endOfCentury()

Resets the date to end of the century and time to 23:59:59.999999

public endOfCentury() : static
Tags
example
echo Carbon::parse('2018-07-25 12:45:16')->endOfCentury();
Return values
static

endOfDay()

Resets the time to 23:59:59.999999 end of day

public endOfDay() : static
Tags
example
echo Carbon::parse('2018-07-25 12:45:16')->endOfDay();
Return values
static

endOfDecade()

Resets the date to end of the decade and time to 23:59:59.999999

public endOfDecade() : static
Tags
example
echo Carbon::parse('2018-07-25 12:45:16')->endOfDecade();
Return values
static

endOfHour()

Modify to end of current hour, minutes and seconds become 59

public endOfHour() : static
Tags
example
echo Carbon::parse('2018-07-25 12:45:16')->endOfHour();
Return values
static

endOfMillennium()

Resets the date to end of the millennium and time to 23:59:59.999999

public endOfMillennium() : static
Tags
example
echo Carbon::parse('2018-07-25 12:45:16')->endOfMillennium();
Return values
static

endOfMillisecond()

Modify to end of current millisecond, microseconds such as 12345 become 123999

public endOfMillisecond() : static
Tags
example
echo Carbon::parse('2018-07-25 12:45:16.334455')
  ->endOfSecond()
  ->format('H:i:s.u');
Return values
static

endOfMinute()

Modify to end of current minute, seconds become 59

public endOfMinute() : static
Tags
example
echo Carbon::parse('2018-07-25 12:45:16')->endOfMinute();
Return values
static

endOfMonth()

Resets the date to end of the month and time to 23:59:59.999999

public endOfMonth() : static
Tags
example
echo Carbon::parse('2018-07-25 12:45:16')->endOfMonth();
Return values
static

endOfQuarter()

Resets the date to end of the quarter and time to 23:59:59.999999

public endOfQuarter() : static
Tags
example
echo Carbon::parse('2018-07-25 12:45:16')->endOfQuarter();
Return values
static

endOfSecond()

Modify to end of current second, microseconds become 999999

public endOfSecond() : static
Tags
example
echo Carbon::parse('2018-07-25 12:45:16.334455')
  ->endOfSecond()
  ->format('H:i:s.u');
Return values
static

endOfWeek()

Resets the date to end of week (defined in $weekEndsAt) and time to 23:59:59.999999

public endOfWeek([WeekDay|int|null $weekEndsAt = null ]) : static
Parameters
$weekEndsAt : WeekDay|int|null = null

optional end allow you to specify the day of week to use to end the week

Tags
example
echo Carbon::parse('2018-07-25 12:45:16')->endOfWeek() . "\n";
echo Carbon::parse('2018-07-25 12:45:16')->locale('ar')->endOfWeek() . "\n";
echo Carbon::parse('2018-07-25 12:45:16')->endOfWeek(Carbon::SATURDAY) . "\n";
Return values
static

endOfYear()

Resets the date to end of the year and time to 23:59:59.999999

public endOfYear() : static
Tags
example
echo Carbon::parse('2018-07-25 12:45:16')->endOfYear();
Return values
static

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

executeWithLocale()

Set the current locale to the given, execute the passed function, reset the locale to previous one, then return the result of the closure (or null if the closure was void).

public static executeWithLocale(string $locale, callable $func) : mixed
Parameters
$locale : string

locale ex. en

$func : callable

farthest()

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

public farthest(Carbon|DateTimeInterface|mixed $date1, Carbon|DateTimeInterface|mixed $date2) : static
Parameters
$date1 : Carbon|DateTimeInterface|mixed
$date2 : Carbon|DateTimeInterface|mixed
Return values
static

firstOfMonth()

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

public firstOfMonth([int|null $dayOfWeek = null ]) : static
Parameters
$dayOfWeek : int|null = null
Return values
static

firstOfQuarter()

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

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

day of the week default null

Return values
static

firstOfYear()

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

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

day of the week default null

Return values
static

floor()

Round the current instance second with given precision if specified.

public floor([DateInterval|string|int|float $precision = 1 ]) : static
Parameters
$precision : DateInterval|string|int|float = 1
Return values
static

floorUnit()

Truncate the current instance at the given unit with given precision if specified.

public floorUnit(string $unit[, DateInterval|string|int|float $precision = 1 ]) : static
Parameters
$unit : string
$precision : DateInterval|string|int|float = 1
Return values
static

floorWeek()

Truncate the current instance week.

public floorWeek([WeekDay|int|null $weekStartsAt = null ]) : static
Parameters
$weekStartsAt : WeekDay|int|null = null

optional start allow you to specify the day of week to use to start the week

Return values
static

from()

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
alias

diffForHumans

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).

Return values
string

fromNow()

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
string

fromSerialized()

Create an instance from a serialized string.

public static fromSerialized(string $value) : static
Parameters
$value : string
Tags
throws
InvalidFormatException
Return values
static

genericMacro()

Register a custom macro.

public static genericMacro(callable $macro[, int $priority = 0 ]) : void
Parameters
$macro : callable
$priority : int = 0

marco with higher priority is tried first

getAltNumber()

Returns the alternative number for a given date property if available in the current locale.

public getAltNumber(string $key) : string
Parameters
$key : string

date property

Return values
string

getAvailableLocales()

Returns the list of internally available locales and already loaded custom locales.

public static getAvailableLocales() : array<string|int, mixed>

(It will ignore custom translator dynamic loading.)

Return values
array<string|int, mixed>

getAvailableLocalesInfo()

Returns list of Language object for each available locale. This object allow you to get the ISO name, native name, region and variant of the locale.

public static getAvailableLocalesInfo() : array<string|int, Language>
Return values
array<string|int, Language>

getCalendarFormats()

Returns list of calendar formats for ISO formatting.

public getCalendarFormats([string|null $locale = null ]) : array<string|int, mixed>
Parameters
$locale : string|null = null

current locale used if null

Return values
array<string|int, mixed>

getDays()

Get the days of the week.

public static getDays() : array<string|int, mixed>
Return values
array<string|int, mixed>

getDaysFromStartOfWeek()

Return the number of days since the start of the week (using the current locale or the first parameter if explicitly given).

public getDaysFromStartOfWeek([WeekDay|int|null $weekStartsAt = null ]) : int
Parameters
$weekStartsAt : WeekDay|int|null = null

optional start allow you to specify the day of week to use to start the week, if not provided, start of week is inferred from the locale (Sunday for en_US, Monday for de_DE, etc.)

Return values
int

getFormatsToIsoReplacements()

List of replacements from date() format to isoFormat().

public static getFormatsToIsoReplacements() : array<string|int, mixed>
Return values
array<string|int, mixed>

getHumanDiffOptions()

Return default humanDiff() options (merged flags as integer).

public static getHumanDiffOptions() : int
Return values
int

getIsoFormats()

Returns list of locale formats for ISO formatting.

public getIsoFormats([string|null $locale = null ]) : array<string|int, mixed>
Parameters
$locale : string|null = null

current locale used if null

Return values
array<string|int, mixed>

getIsoUnits()

Returns list of locale units for ISO formatting.

public static getIsoUnits() : array<string|int, mixed>
Return values
array<string|int, mixed>

getLastErrors()

{@inheritdoc}

public static getLastErrors() : array<string|int, mixed>|false
Return values
array<string|int, mixed>|false

getLocale()

Get the current translator locale.

public static getLocale() : string
Return values
string

getLocalMacro()

Get the raw callable macro registered globally or locally for a given name.

public getLocalMacro(string $name) : callable|null
Parameters
$name : string
Return values
callable|null

getLocalTranslator()

Get the translator of the current instance or the default if none set.

public getLocalTranslator() : TranslatorInterface
Return values
TranslatorInterface

getMacro()

Get the raw callable macro registered globally for a given name.

public static getMacro(string $name) : callable|null
Parameters
$name : string
Return values
callable|null

getMidDayAt()

get midday/noon hour

public static getMidDayAt() : int
Return values
int

getOffsetString()

Returns the offset hour and minute formatted with +/- and a given separator (":" by default).

public getOffsetString([string $separator = ':' ]) : string

For example, if the time zone is 9 hours 30 minutes, you'll get "+09:30", with "@@" as first argument, "+09@@30", with "" as first argument, "+0930". Negative offset will return something like "-12:00".

Parameters
$separator : string = ':'

string to place between hours and minutes (":" by default)

Return values
string

getPaddedUnit()

Returns a unit of the instance padded with 0 by default or any other string if specified.

public getPaddedUnit(string $unit[, int $length = 2 ][, string $padString = '0' ][, int $padType = 0 ]) : string
Parameters
$unit : string

Carbon unit name

$length : int = 2

Length of the output (2 by default)

$padString : string = '0'

String to use for padding ("0" by default)

$padType : int = 0

Side(s) to pad (STR_PAD_LEFT by default)

Return values
string

getPreciseTimestamp()

Returns a timestamp rounded with the given precision (6 by default).

public getPreciseTimestamp([int $precision = 6 ]) : float
Parameters
$precision : int = 6
Tags
example

getPreciseTimestamp() 1532087464437474 (microsecond maximum precision)

example

getPreciseTimestamp(6) 1532087464437474

example

getPreciseTimestamp(5) 153208746443747 (1/100000 second precision)

example

getPreciseTimestamp(4) 15320874644375 (1/10000 second precision)

example

getPreciseTimestamp(3) 1532087464437 (millisecond precision)

example

getPreciseTimestamp(2) 153208746444 (1/100 second precision)

example

getPreciseTimestamp(1) 15320874644 (1/10 second precision)

example

getPreciseTimestamp(0) 1532087464 (second precision)

example

getPreciseTimestamp(-1) 153208746 (10 second precision)

example

getPreciseTimestamp(-2) 15320875 (100 second precision)

Return values
float

getSettings()

Returns current local settings.

public getSettings() : array<string|int, mixed>
Return values
array<string|int, mixed>

getTestNow()

Get the Carbon instance (real or mock) to be returned when a "now" instance is created.

public static getTestNow() : Closure|self|null
Return values
Closure|self|null

the current instance used for testing

getTimeFormatByPrecision()

Return a format from H:i to H:i:s.u according to given unit precision.

public static getTimeFormatByPrecision(string $unitPrecision) : string
Parameters
$unitPrecision : string

"minute", "second", "millisecond" or "microsecond"

Return values
string

getTimestampMs()

Returns the timestamp with millisecond precision.

public getTimestampMs() : int
Return values
int

getTranslatedDayName()

Get the translation of the current week day name (with context for languages with multiple forms).

public getTranslatedDayName([string|null $context = null ][, string $keySuffix = '' ][, string|null $defaultValue = null ]) : string
Parameters
$context : string|null = null

whole format string

$keySuffix : string = ''

"", "_short" or "_min"

$defaultValue : string|null = null

default value if translation missing

Return values
string

getTranslatedMinDayName()

Get the translation of the current abbreviated week day name (with context for languages with multiple forms).

public getTranslatedMinDayName([string|null $context = null ]) : string
Parameters
$context : string|null = null

whole format string

Return values
string

getTranslatedMonthName()

Get the translation of the current month day name (with context for languages with multiple forms).

public getTranslatedMonthName([string|null $context = null ][, string $keySuffix = '' ][, string|null $defaultValue = null ]) : string
Parameters
$context : string|null = null

whole format string

$keySuffix : string = ''

"" or "_short"

$defaultValue : string|null = null

default value if translation missing

Return values
string

getTranslatedShortDayName()

Get the translation of the current short week day name (with context for languages with multiple forms).

public getTranslatedShortDayName([string|null $context = null ]) : string
Parameters
$context : string|null = null

whole format string

Return values
string

getTranslatedShortMonthName()

Get the translation of the current short month day name (with context for languages with multiple forms).

public getTranslatedShortMonthName([string|null $context = null ]) : string
Parameters
$context : string|null = null

whole format string

Return values
string

getTranslationMessage()

Returns raw translation message for a given key.

public getTranslationMessage(string $key[, string|null $locale = null ][, string|null $default = null ][, TranslatorInterface $translator = null ]) : string
Parameters
$key : string

key to find

$locale : string|null = null

current locale used if null

$default : string|null = null

default value if translation returns the key

$translator : TranslatorInterface = null

an optional translator to use

Return values
string

getTranslationMessageWith()

Returns raw translation message for a given key.

public static getTranslationMessageWith(TranslatorInterface|null $translator, string $key[, string|null $locale = null ][, string|null $default = null ]) : string|Closure|null
Parameters
$translator : TranslatorInterface|null

the translator to use

$key : string

key to find

$locale : string|null = null

current locale used if null

$default : string|null = null

default value if translation returns the key

Return values
string|Closure|null

getTranslator()

Initialize the default translator instance if necessary.

public static getTranslator() : TranslatorInterface
Return values
TranslatorInterface

getWeekendDays()

Get weekend days

public static getWeekendDays() : array<string|int, mixed>
Return values
array<string|int, mixed>

getWeekEndsAt()

Get the last day of week.

public static getWeekEndsAt([string $locale = null ]) : int
Parameters
$locale : string = null

local to consider the last day of week.

Return values
int

getWeekStartsAt()

Get the first day of week.

public static getWeekStartsAt([string|null $locale = null ]) : int
Parameters
$locale : string|null = null
Return values
int

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

hasLocalMacro()

Checks if macro is registered globally or locally.

public hasLocalMacro(string $name) : bool
Parameters
$name : string
Return values
bool

hasLocalTranslator()

Return true if the current instance has its own translator.

public hasLocalTranslator() : bool
Return values
bool

hasMacro()

Checks if macro is registered globally.

public static hasMacro(string $name) : bool
Parameters
$name : string
Return values
bool

hasRelativeKeywords()

Determine if a time string will produce a relative date.

public static hasRelativeKeywords(string|null $time) : bool
Parameters
$time : string|null
Return values
bool

true if time match a relative date, false if absolute or invalid time string

hasTestNow()

Determine if there is a valid test instance set. A valid test instance is anything that is not null.

public static hasTestNow() : bool
Return values
bool

true if there is a test instance, otherwise false

instance()

Create a Carbon instance from a DateTime one.

public static instance(DateTimeInterface $date) : static
Parameters
$date : DateTimeInterface
Return values
static

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

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

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

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

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

isImmutable()

Returns true if the current class/instance is immutable.

public static isImmutable() : bool
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

isModifiableUnit()

Returns true if a property can be changed via setter.

public static isModifiableUnit(string $unit) : bool
Parameters
$unit : string
Return values
bool

isMutable()

Returns true if the current class/instance is mutable.

public static isMutable() : bool
Return values
bool

isoFormat()

Format in the current language using ISO replacement patterns.

public isoFormat(string $format[, string|null $originalFormat = null ]) : string
Parameters
$format : string
$originalFormat : string|null = null

provide context if a chunk has been passed alone

Return values
string

isoWeek()

Get/set the week number using given first day of week and first day of year included in the first week. Or use ISO format if no settings given.

public isoWeek([int|null $week = null ][, int|null $dayOfWeek = null ][, int|null $dayOfYear = null ]) : int|static
Parameters
$week : int|null = null
$dayOfWeek : int|null = null
$dayOfYear : int|null = null
Return values
int|static

isoWeekday()

Get/set the ISO weekday from 1 (Monday) to 7 (Sunday).

public isoWeekday([WeekDay|int|null $value = null ]) : static|int
Parameters
$value : WeekDay|int|null = null

new value for weekday if using as setter.

Return values
static|int

isoWeeksInYear()

Get the number of weeks of the current week-year using given first day of week and first day of year included in the first week. Or use ISO format if no settings given.

public isoWeeksInYear([int|null $dayOfWeek = null ][, int|null $dayOfYear = null ]) : int
Parameters
$dayOfWeek : int|null = null

first date of week from 0 (Sunday) to 6 (Saturday)

$dayOfYear : int|null = null

first day of year included in the week #1

Return values
int

isoWeekYear()

Set/get the week number of year using given first day of week and first day of year included in the first week. Or use ISO format if no settings given.

public isoWeekYear([int|null $year = null ][, int|null $dayOfWeek = null ][, int|null $dayOfYear = null ]) : int|static
Parameters
$year : int|null = null

if null, act as a getter, if not null, set the year and return current instance.

$dayOfWeek : int|null = null

first date of week from 0 (Sunday) to 6 (Saturday)

$dayOfYear : int|null = null

first day of year included in the week #1

Return values
int|static

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

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

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

isStrictModeEnabled()

Returns true if the strict mode is globally in use, false else.

public static isStrictModeEnabled() : bool

(It can be overridden in specific instances.)

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

jsonSerialize()

Prepare the object for JSON serialization.

public jsonSerialize() : mixed

lastOfMonth()

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

public lastOfMonth([int|null $dayOfWeek = null ]) : static
Parameters
$dayOfWeek : int|null = null
Return values
static

lastOfQuarter()

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

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

day of the week default null

Return values
static

lastOfYear()

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

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

day of the week default null

Return values
static

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

locale()

Get/set the locale for the current instance.

public locale([string|null $locale = null ], string ...$fallbackLocales) : $this|string
Parameters
$locale : string|null = null
$fallbackLocales : string
Return values
$this|string

localeHasDiffOneDayWords()

Returns true if the given locale is internally supported and has words for 1-day diff (just now, yesterday, tomorrow).

public static localeHasDiffOneDayWords(string $locale) : bool

Support is considered enabled if the 3 words are translated in the given locale.

Parameters
$locale : string

locale ex. en

Return values
bool

localeHasDiffSyntax()

Returns true if the given locale is internally supported and has diff syntax support (ago, from now, before, after).

public static localeHasDiffSyntax(string $locale) : bool

Support is considered enabled if the 4 sentences are translated in the given locale.

Parameters
$locale : string

locale ex. en

Return values
bool

localeHasDiffTwoDayWords()

Returns true if the given locale is internally supported and has words for 2-days diff (before yesterday, after tomorrow).

public static localeHasDiffTwoDayWords(string $locale) : bool

Support is considered enabled if the 2 words are translated in the given locale.

Parameters
$locale : string

locale ex. en

Return values
bool

localeHasPeriodSyntax()

Returns true if the given locale is internally supported and has period syntax support (X times, every X, from X, to X).

public static localeHasPeriodSyntax(string $locale) : bool

Support is considered enabled if the 4 sentences are translated in the given locale.

Parameters
$locale : string

locale ex. en

Return values
bool

localeHasShortUnits()

Returns true if the given locale is internally supported and has short-units support.

public static localeHasShortUnits(string $locale) : bool

Support is considered enabled if either year, day or hour has a short variant translated.

Parameters
$locale : string

locale ex. en

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

macro()

Register a custom macro.

public static macro(string $name, callable|null $macro) : void

Pass null macro to remove it.

Parameters
$name : string
$macro : callable|null
Tags
example
$userSettings = [
  'locale' => 'pt',
  'timezone' => 'America/Sao_Paulo',
];
Carbon::macro('userFormat', function () use ($userSettings) {
  return $this->copy()->locale($userSettings['locale'])->tz($userSettings['timezone'])->calendar();
});
echo Carbon::yesterday()->hours(11)->userFormat();

make()

Make a Carbon instance from given variable if possible.

public static make(mixed $var[, DateTimeZone|string|null $timezone = null ]) : static|null

Always return a new instance. Parse only strings and only these likely to be dates (skip intervals and recurrences). Throw an exception for invalid format, but otherwise return null.

Parameters
$var : mixed
$timezone : DateTimeZone|string|null = null
Tags
throws
InvalidFormatException
Return values
static|null

max()

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

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

maximum()

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

public maximum([Carbon|DateTimeInterface|mixed $date = null ]) : static
Parameters
$date : Carbon|DateTimeInterface|mixed = null
Tags
see
max()
Return values
static

meridiem()

Return the meridiem of the current time in the current locale.

public meridiem([bool $isLower = false ]) : string
Parameters
$isLower : bool = false

if true, returns lowercase variant if available in the current locale.

Return values
string

midDay()

Modify to midday, default to self::$midDayAt

public midDay() : static
Return values
static

min()

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

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

minimum()

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

public minimum([Carbon|DateTimeInterface|mixed $date = null ]) : static
Parameters
$date : Carbon|DateTimeInterface|mixed = null
Tags
see
min()
Return values
static

mixin()

Mix another object into the class.

public static mixin(object|string $mixin) : void
Parameters
$mixin : object|string
Tags
example
Carbon::mixin(new class {
  public function addMoon() {
    return function () {
      return $this->addDays(30);
    };
  }
  public function subMoon() {
    return function () {
      return $this->subDays(30);
    };
  }
});
$fullMoon = Carbon::create('2018-12-22');
$nextFullMoon = $fullMoon->addMoon();
$blackMoon = Carbon::create('2019-01-06');
$previousBlackMoon = $blackMoon->subMoon();
echo "$nextFullMoon\n";
echo "$previousBlackMoon\n";
throws
ReflectionException

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

next()

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

public next([string|int|null $modifier = null ]) : static
Parameters
$modifier : string|int|null = null
Return values
static

nextWeekday()

Go forward to the next weekday.

public nextWeekday() : static
Return values
static

nextWeekendDay()

Go forward to the next weekend day.

public nextWeekendDay() : static
Return values
static

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

now()

Get a Carbon instance for the current date and time.

public static now([DateTimeZone|string|int|null $timezone = null ]) : static
Parameters
$timezone : DateTimeZone|string|int|null = null
Return values
static

nowWithSameTz()

Returns a present instance in the same timezone.

public nowWithSameTz() : static
Return values
static

nthOfMonth()

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

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

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

Parameters
$nth : int
$dayOfWeek : int

nthOfQuarter()

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

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

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

Parameters
$nth : int
$dayOfWeek : int

nthOfYear()

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

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

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

Parameters
$nth : int
$dayOfWeek : int

ordinal()

Return a property with its ordinal.

public ordinal(string $key[, string|null $period = null ]) : string
Parameters
$key : string
$period : string|null = null
Return values
string

parse()

Create a carbon instance from a string.

public static parse(DateTimeInterface|WeekDay|Month|string|int|float|null $time[, DateTimeZone|string|int|null $timezone = null ]) : static

This is an alias for the constructor that allows better fluent syntax as it allows you to do Carbon::parse('Monday next week')->fn() rather than (new Carbon('Monday next week'))->fn().

Parameters
$time : DateTimeInterface|WeekDay|Month|string|int|float|null
$timezone : DateTimeZone|string|int|null = null
Tags
throws
InvalidFormatException
Return values
static

parseFromLocale()

Create a carbon instance from a localized string (in French, Japanese, Arabic, etc.).

public static parseFromLocale(string $time[, string|null $locale = null ][, DateTimeZone|string|int|null $timezone = null ]) : static
Parameters
$time : string

date/time string in the given language (may also contain English).

$locale : string|null = null

if locale is null or not specified, current global locale will be used instead.

$timezone : DateTimeZone|string|int|null = null

optional timezone for the new instance.

Tags
throws
InvalidFormatException
Return values
static

pluralUnit()

Returns standardized plural of a given singular/plural unit name (in English).

public static pluralUnit(string $unit) : string
Parameters
$unit : string
Return values
string

previous()

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

public previous([string|int|null $modifier = null ]) : static
Parameters
$modifier : string|int|null = null
Return values
static

previousWeekday()

Go backward to the previous weekday.

public previousWeekday() : static
Return values
static

previousWeekendDay()

Go backward to the previous weekend day.

public previousWeekendDay() : static
Return values
static

range()

Create a iterable CarbonPeriod object from current date to a given end date (and optional interval).

public range([DateTimeInterface|Carbon|CarbonImmutable|null $end = null ][, int|DateInterval|string|null $interval = null ][, string|null $unit = null ]) : CarbonPeriod
Parameters
$end : DateTimeInterface|Carbon|CarbonImmutable|null = null

period end date

$interval : int|DateInterval|string|null = null

period default interval or number of the given $unit

$unit : string|null = null

if specified, $interval must be an integer

Return values
CarbonPeriod

rawAdd()

Call native PHP DateTime/DateTimeImmutable add() method.

public rawAdd(DateInterval $interval) : static
Parameters
$interval : DateInterval
Return values
static

rawCreateFromFormat()

Create a Carbon instance from a specific format.

public static rawCreateFromFormat(string $format, string $time[, DateTimeZone|string|int|null $timezone = null ]) : static|null
Parameters
$format : string

Datetime format

$time : string
$timezone : DateTimeZone|string|int|null = null
Tags
throws
InvalidFormatException
Return values
static|null

rawParse()

Create a carbon instance from a string.

public static rawParse(DateTimeInterface|WeekDay|Month|string|int|float|null $time[, DateTimeZone|string|int|null $timezone = null ]) : static

This is an alias for the constructor that allows better fluent syntax as it allows you to do Carbon::parse('Monday next week')->fn() rather than (new Carbon('Monday next week'))->fn().

Parameters
$time : DateTimeInterface|WeekDay|Month|string|int|float|null
$timezone : DateTimeZone|string|int|null = null
Tags
throws
InvalidFormatException
Return values
static

rawSub()

Call native PHP DateTime/DateTimeImmutable sub() method.

public rawSub(DateInterval $interval) : static
Parameters
$interval : DateInterval
Return values
static

resetMacros()

Remove all macros and generic macros.

public static resetMacros() : void

resetMonthsOverflow()

public static resetMonthsOverflow() : void
Tags
deprecated

To avoid conflict between different third-party libraries, static setters should not be used. You should rather use the ->settings() method. Or you can use method variants: addMonthsWithOverflow/addMonthsNoOverflow, same variants are available for quarters, years, decade, centuries, millennia (singular and plural forms).

see
settings

Reset the month overflow behavior.

resetToStringFormat()

Reset the format used to the default when type juggling a Carbon instance to a string

public static resetToStringFormat() : void

resetYearsOverflow()

public static resetYearsOverflow() : void
Tags
deprecated

To avoid conflict between different third-party libraries, static setters should not be used. You should rather use the ->settings() method. Or you can use method variants: addYearsWithOverflow/addYearsNoOverflow, same variants are available for quarters, years, decade, centuries, millennia (singular and plural forms).

see
settings

Reset the month overflow behavior.

round()

Round the current instance second with given precision if specified.

public round([DateInterval|string|int|float $precision = 1 ][, callable|string $function = 'round' ]) : static
Parameters
$precision : DateInterval|string|int|float = 1
$function : callable|string = 'round'
Return values
static

roundUnit()

Round the current instance at the given unit with given precision if specified and the given function.

public roundUnit(string $unit[, DateInterval|string|int|float $precision = 1 ][, callable|string $function = 'round' ]) : static
Parameters
$unit : string
$precision : DateInterval|string|int|float = 1
$function : callable|string = 'round'
Return values
static

roundWeek()

Round the current instance week.

public roundWeek([WeekDay|int|null $weekStartsAt = null ]) : static
Parameters
$weekStartsAt : WeekDay|int|null = null

optional start allow you to specify the day of week to use to start the week

Return values
static

secondsSinceMidnight()

The number of seconds since midnight.

public secondsSinceMidnight() : float
Return values
float

secondsUntilEndOfDay()

The number of seconds until 23:59:59.

public secondsUntilEndOfDay() : float
Return values
float

serialize()

Return a serialized string of the instance.

public serialize() : string
Return values
string

serializeUsing()

public static serializeUsing(callable|string|null $format) : void
Parameters
$format : callable|string|null
Tags
deprecated

To avoid conflict between different third-party libraries, static setters should not be used. You should rather transform Carbon object before the serialization.

JSON serialize all Carbon instances using the given callback.

setDateFrom()

Set the year, month, and date for this instance to that of the passed instance.

public setDateFrom(DateTimeInterface|string $date) : static
Parameters
$date : DateTimeInterface|string
Return values
static

setDateTime()

Set the date and time all together.

public setDateTime(int $year, int $month, int $day, int $hour, int $minute[, int $second = 0 ][, int $microseconds = 0 ]) : static
Parameters
$year : int
$month : int
$day : int
$hour : int
$minute : int
$second : int = 0
$microseconds : int = 0
Return values
static

setDateTimeFrom()

Set the date and time for this instance to that of the passed instance.

public setDateTimeFrom(DateTimeInterface|string $date) : static
Parameters
$date : DateTimeInterface|string
Return values
static

setDaysFromStartOfWeek()

Set the day (keeping the current time) to the start of the week + the number of days passed as the first parameter. First day of week is driven by the locale unless explicitly set with the second parameter.

public setDaysFromStartOfWeek(int $numberOfDays[, WeekDay|int|null $weekStartsAt = null ]) : static
Parameters
$numberOfDays : int

number of days to add after the start of the current week

$weekStartsAt : WeekDay|int|null = null

optional start allow you to specify the day of week to use to start the week, if not provided, start of week is inferred from the locale (Sunday for en_US, Monday for de_DE, etc.)

Return values
static

setHumanDiffOptions()

public static setHumanDiffOptions(int $humanDiffOptions) : void
Parameters
$humanDiffOptions : int
Tags
deprecated

To avoid conflict between different third-party libraries, static setters should not be used. You should rather use the ->settings() method.

see
settings

setISODate()

Set a date according to the ISO 8601 standard - using weeks and day offsets rather than specific dates.

public setISODate(int $year, int $week[, int $day = 1 ]) : static
Parameters
$year : int
$week : int
$day : int = 1
Tags
see
https://php.net/manual/en/datetime.setisodate.php
Return values
static

setLocale()

Set the current translator locale and indicate if the source locale file exists.

public static setLocale(string $locale) : void

Pass 'auto' as locale to use the closest language to the current LC_TIME locale.

Parameters
$locale : string

locale ex. en

setLocalTranslator()

Set the translator for the current instance.

public setLocalTranslator(TranslatorInterface $translator) : mixed
Parameters
$translator : TranslatorInterface

setMidDayAt()

public static setMidDayAt(int $hour) : void
Parameters
$hour : int

midday hour

Tags
deprecated

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

Set midday/noon hour

setTestNow()

Set a Carbon instance (real or mock) to be returned when a "now" instance is created. The provided instance will be returned specifically under the following conditions: - A call to the static now() method, ex. Carbon::now() - When a null (or blank string) is passed to the constructor or parse(), ex. new Carbon(null) - When the string "now" is passed to the constructor or parse(), ex. new Carbon('now') - When a string containing the desired time is passed to Carbon::parse().

public static setTestNow([DateTimeInterface|Closure|static|string|false|null $testNow = null ]) : void

Note the timezone parameter was left out of the examples above and has no affect as the mock value will be returned regardless of its value.

Only the moment is mocked with setTestNow(), the timezone will still be the one passed as parameter of date_default_timezone_get() as a fallback (see setTestNowAndTimezone()).

To clear the test instance call this method using the default parameter of null.

/!\ Use this method for unit tests only.

Parameters
$testNow : DateTimeInterface|Closure|static|string|false|null = null

real or mock Carbon instance

setTestNowAndTimezone()

Set a Carbon instance (real or mock) to be returned when a "now" instance is created. The provided instance will be returned specifically under the following conditions: - A call to the static now() method, ex. Carbon::now() - When a null (or blank string) is passed to the constructor or parse(), ex. new Carbon(null) - When the string "now" is passed to the constructor or parse(), ex. new Carbon('now') - When a string containing the desired time is passed to Carbon::parse().

public static setTestNowAndTimezone([DateTimeInterface|Closure|static|string|false|null $testNow = null ][, mixed $timezone = null ]) : void

It will also align default timezone (e.g. call date_default_timezone_set()) with the second argument or if null, with the timezone of the given date object.

To clear the test instance call this method using the default parameter of null.

/!\ Use this method for unit tests only.

Parameters
$testNow : DateTimeInterface|Closure|static|string|false|null = null

real or mock Carbon instance

$timezone : mixed = null

setTime()

Resets the current time of the DateTime object to a different time.

public setTime(int $hour, int $minute[, int $second = 0 ][, int $microseconds = 0 ]) : static
Parameters
$hour : int
$minute : int
$second : int = 0
$microseconds : int = 0
Tags
see
https://php.net/manual/en/datetime.settime.php
Return values
static

setTimeFrom()

Set the hour, minute, second and microseconds for this instance to that of the passed instance.

public setTimeFrom(DateTimeInterface|string $date) : static
Parameters
$date : DateTimeInterface|string
Return values
static

setTimeFromTimeString()

Set the time by time string.

public setTimeFromTimeString(string $time) : static
Parameters
$time : string
Return values
static

setTimestamp()

Set the instance's timestamp.

public setTimestamp(string|int|float $timestamp) : static

Timestamp input can be given as int, float or a string containing one or more numbers.

Parameters
$timestamp : string|int|float
Return values
static

setTimezone()

Set the instance's timezone from a string or object.

public setTimezone(DateTimeZone|string|int $timeZone) : static
Parameters
$timeZone : DateTimeZone|string|int
Return values
static

settings()

Set specific options.

public settings(array<string|int, mixed> $settings) : $this|static
  • strictMode: true|false|null
  • monthOverflow: true|false|null
  • yearOverflow: true|false|null
  • humanDiffOptions: int|null
  • toStringFormat: string|Closure|null
  • toJsonFormat: string|Closure|null
  • locale: string|null
  • timezone: \DateTimeZone|string|int|null
  • macros: array|null
  • genericMacros: array|null
Parameters
$settings : array<string|int, mixed>
Return values
$this|static

setToStringFormat()

public static setToStringFormat(string|Closure|null $format) : void
Parameters
$format : string|Closure|null
Tags
deprecated

To avoid conflict between different third-party libraries, static setters should not be used. You should rather let Carbon object being cast to string with DEFAULT_TO_STRING_FORMAT, and use other method or custom format passed to format() method if you need to dump another string format.

Set the default format used when type juggling a Carbon instance to a string.

setTranslator()

Set the default translator instance to use.

public static setTranslator(TranslatorInterface $translator) : void
Parameters
$translator : TranslatorInterface

setUnit()

Set specified unit to new given value.

public setUnit(string $unit[, Month|int $value = null ]) : static
Parameters
$unit : string

year, month, day, hour, minute, second or microsecond

$value : Month|int = null

new value for given unit

Return values
static

setUnitNoOverflow()

Set any unit to a new value without overflowing current other unit given.

public setUnitNoOverflow(string $valueUnit, int $value, string $overflowUnit) : static
Parameters
$valueUnit : string

unit name to modify

$value : int

new value for the input unit

$overflowUnit : string

unit name to not overflow

Return values
static

setWeekendDays()

public static setWeekendDays(array<string|int, mixed> $days) : void
Parameters
$days : array<string|int, mixed>
Tags
deprecated

To avoid conflict between different third-party libraries, static setters should not be used. You should rather consider week-end is always saturday and sunday, and if you have some custom week-end days to handle, give to those days an other name and create a macro for them:

        ```
        Carbon::macro('isDayOff', function ($date) {
            return $date->isSunday() || $date->isMonday();
        });
        Carbon::macro('isNotDayOff', function ($date) {
            return !$date->isDayOff();
        });
        if ($someDate->isDayOff()) ...
        if ($someDate->isNotDayOff()) ...
        // Add 5 not-off days
        $count = 5;
        while ($someDate->isDayOff() || ($count-- > 0)) {
            $someDate->addDay();
        }
        ```

Set weekend days

shiftTimezone()

Set the instance's timezone from a string or object and add/subtract the offset difference.

public shiftTimezone(DateTimeZone|string $value) : static
Parameters
$value : DateTimeZone|string
Return values
static

shouldOverflowMonths()

Get the month overflow global behavior (can be overridden in specific instances).

public static shouldOverflowMonths() : bool
Return values
bool

shouldOverflowYears()

Get the month overflow global behavior (can be overridden in specific instances).

public static shouldOverflowYears() : bool
Return values
bool

since()

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
alias

diffForHumans

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).

singularUnit()

Returns standardized singular of a given singular/plural unit name (in English).

public static singularUnit(string $unit) : string
Parameters
$unit : string
Return values
string

sleep()

public static sleep(int|float $seconds) : void
Parameters
$seconds : int|float

startOf()

Modify to start of current given unit.

public startOf(Unit|string $unit, mixed ...$params) : static
Parameters
$unit : Unit|string
$params : mixed
Tags
example
echo Carbon::parse('2018-07-25 12:45:16.334455')
  ->startOf(Unit::Month)
  ->endOf(Unit::Week, Carbon::FRIDAY);
Return values
static

startOfCentury()

Resets the date to the first day of the century and the time to 00:00:00

public startOfCentury() : static
Tags
example
echo Carbon::parse('2018-07-25 12:45:16')->startOfCentury();
Return values
static

startOfDay()

Resets the time to 00:00:00 start of day

public startOfDay() : static
Tags
example
echo Carbon::parse('2018-07-25 12:45:16')->startOfDay();
Return values
static

startOfDecade()

Resets the date to the first day of the decade and the time to 00:00:00

public startOfDecade() : static
Tags
example
echo Carbon::parse('2018-07-25 12:45:16')->startOfDecade();
Return values
static

startOfHour()

Modify to start of current hour, minutes and seconds become 0

public startOfHour() : static
Tags
example
echo Carbon::parse('2018-07-25 12:45:16')->startOfHour();
Return values
static

startOfMillennium()

Resets the date to the first day of the millennium and the time to 00:00:00

public startOfMillennium() : static
Tags
example
echo Carbon::parse('2018-07-25 12:45:16')->startOfMillennium();
Return values
static

startOfMillisecond()

Modify to start of current millisecond, microseconds such as 12345 become 123000

public startOfMillisecond() : static
Tags
example
echo Carbon::parse('2018-07-25 12:45:16.334455')
  ->startOfSecond()
  ->format('H:i:s.u');
Return values
static

startOfMinute()

Modify to start of current minute, seconds become 0

public startOfMinute() : static
Tags
example
echo Carbon::parse('2018-07-25 12:45:16')->startOfMinute();
Return values
static

startOfMonth()

Resets the date to the first day of the month and the time to 00:00:00

public startOfMonth() : static
Tags
example
echo Carbon::parse('2018-07-25 12:45:16')->startOfMonth();
Return values
static

startOfQuarter()

Resets the date to the first day of the quarter and the time to 00:00:00

public startOfQuarter() : static
Tags
example
echo Carbon::parse('2018-07-25 12:45:16')->startOfQuarter();
Return values
static

startOfSecond()

Modify to start of current second, microseconds become 0

public startOfSecond() : static
Tags
example
echo Carbon::parse('2018-07-25 12:45:16.334455')
  ->startOfSecond()
  ->format('H:i:s.u');
Return values
static

startOfWeek()

Resets the date to the first day of week (defined in $weekStartsAt) and the time to 00:00:00

public startOfWeek([WeekDay|int|null $weekStartsAt = null ]) : static
Parameters
$weekStartsAt : WeekDay|int|null = null

optional start allow you to specify the day of week to use to start the week

Tags
example
echo Carbon::parse('2018-07-25 12:45:16')->startOfWeek() . "\n";
echo Carbon::parse('2018-07-25 12:45:16')->locale('ar')->startOfWeek() . "\n";
echo Carbon::parse('2018-07-25 12:45:16')->startOfWeek(Carbon::SUNDAY) . "\n";
Return values
static

startOfYear()

Resets the date to the first day of the year and the time to 00:00:00

public startOfYear() : static
Tags
example
echo Carbon::parse('2018-07-25 12:45:16')->startOfYear();
Return values
static

sub()

Subtract given units or interval to the current instance.

public sub(Unit|string|DateInterval|Closure|CarbonConverterInterface $unit[, int|float $value = 1 ][, bool|null $overflow = null ]) : static
Parameters
$unit : Unit|string|DateInterval|Closure|CarbonConverterInterface
$value : int|float = 1
$overflow : bool|null = null
Tags
example

$date->sub('hour', 3)

example

$date->sub(15, 'days')

example

$date->sub(CarbonInterval::days(4))

Return values
static

subRealUnit()

public subRealUnit(string $unit[, int $value = 1 ]) : static
Parameters
$unit : string
$value : int = 1
Tags
deprecated

Prefer to use add subUTCUnit() which more accurately defines what it's doing.

Subtract seconds to the instance using timestamp. Positive $value travels into the past while negative $value travels forward.

Return values
static

subtract()

Subtract given units or interval to the current instance.

public subtract(string|DateInterval $unit[, int|float $value = 1 ][, bool|null $overflow = null ]) : static
Parameters
$unit : string|DateInterval
$value : int|float = 1
$overflow : bool|null = null
Tags
see
sub()
Return values
static

subUnit()

Subtract given units to the current instance.

public subUnit(Unit|string $unit[, mixed $value = 1 ][, bool|null $overflow = null ]) : static
Parameters
$unit : Unit|string
$value : mixed = 1
$overflow : bool|null = null
Return values
static

subUnitNoOverflow()

Subtract any unit to a new value without overflowing current other unit given.

public subUnitNoOverflow(string $valueUnit, int $value, string $overflowUnit) : static
Parameters
$valueUnit : string

unit name to modify

$value : int

amount to subtract to the input unit

$overflowUnit : string

unit name to not overflow

Return values
static

subUTCUnit()

Subtract seconds to the instance using timestamp. Positive $value travels into the past while negative $value travels forward.

public subUTCUnit(string $unit[, int $value = 1 ]) : static
Parameters
$unit : string
$value : int = 1
Return values
static

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
string

timestamp()

Set the instance's timestamp.

public timestamp(string|int|float $timestamp) : static

Timestamp input can be given as int, float or a string containing one or more numbers.

Parameters
$timestamp : string|int|float
Return values
static

timezone()

public timezone(DateTimeZone|string|int $value) : static
Parameters
$value : DateTimeZone|string|int
Tags
alias

setTimezone

Return values
static

to()

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
string

toArray()

Get default array representation.

public toArray() : array<string|int, mixed>
Tags
example
var_dump(Carbon::now()->toArray());
Return values
array<string|int, mixed>

toAtomString()

Format the instance as ATOM

public toAtomString() : string
Tags
example
echo Carbon::now()->toAtomString();
Return values
string

toCookieString()

Format the instance as COOKIE

public toCookieString() : string
Tags
example
echo Carbon::now()->toCookieString();
Return values
string

toDate()

public toDate() : DateTime
Tags
alias

toDateTime

Return native DateTime PHP object matching the current instance.

example
var_dump(Carbon::now()->toDate());
Return values
DateTime

toDateString()

Format the instance as date

public toDateString() : string
Tags
example
echo Carbon::now()->toDateString();
Return values
string

toDateTime()

Return native DateTime PHP object matching the current instance.

public toDateTime() : DateTime
Tags
example
var_dump(Carbon::now()->toDateTime());
Return values
DateTime

toDateTimeImmutable()

Return native toDateTimeImmutable PHP object matching the current instance.

public toDateTimeImmutable() : DateTimeImmutable
Tags
example
var_dump(Carbon::now()->toDateTimeImmutable());
Return values
DateTimeImmutable

toDateTimeLocalString()

Format the instance as date and time T-separated with no timezone

public toDateTimeLocalString([string $unitPrecision = 'second' ]) : string
Parameters
$unitPrecision : string = 'second'
Tags
example
echo Carbon::now()->toDateTimeLocalString();
echo "\n";
echo Carbon::now()->toDateTimeLocalString('minute'); // You can specify precision among: minute, second, millisecond and microsecond
Return values
string

toDateTimeString()

Format the instance as date and time

public toDateTimeString([string $unitPrecision = 'second' ]) : string
Parameters
$unitPrecision : string = 'second'
Tags
example
echo Carbon::now()->toDateTimeString();
Return values
string

today()

Create a Carbon instance for today.

public static today([DateTimeZone|string|int|null $timezone = null ]) : static
Parameters
$timezone : DateTimeZone|string|int|null = null
Return values
static

toDayDateTimeString()

Format the instance with day, date and time

public toDayDateTimeString() : string
Tags
example
echo Carbon::now()->toDayDateTimeString();
Return values
string

toFormattedDateString()

Format the instance as a readable date

public toFormattedDateString() : string
Tags
example
echo Carbon::now()->toFormattedDateString();
Return values
string

toFormattedDayDateString()

Format the instance with the day, and a readable date

public toFormattedDayDateString() : string
Tags
example
echo Carbon::now()->toFormattedDayDateString();
Return values
string

toIso8601String()

Format the instance as ISO8601

public toIso8601String() : string
Tags
example
echo Carbon::now()->toIso8601String();
Return values
string

toIso8601ZuluString()

Convert the instance to UTC and return as Zulu ISO8601

public toIso8601ZuluString([string $unitPrecision = 'second' ]) : string
Parameters
$unitPrecision : string = 'second'
Tags
example
echo Carbon::now()->toIso8601ZuluString();
Return values
string

toISOString()

Return the ISO-8601 string (ex: 1977-04-22T06:00:00Z, if $keepOffset truthy, offset will be kept: 1977-04-22T01:00:00-05:00).

public toISOString([bool $keepOffset = false ]) : string|null
Parameters
$keepOffset : bool = false

Pass true to keep the date offset. Else forced to UTC.

Tags
example
echo Carbon::now('America/Toronto')->toISOString() . "\n";
echo Carbon::now('America/Toronto')->toISOString(true) . "\n";
Return values
string|null

toJSON()

Return the ISO-8601 string (ex: 1977-04-22T06:00:00Z) with UTC timezone.

public toJSON() : string|null
Tags
example
echo Carbon::now('America/Toronto')->toJSON();
Return values
string|null

tomorrow()

Create a Carbon instance for tomorrow.

public static tomorrow([DateTimeZone|string|int|null $timezone = null ]) : static
Parameters
$timezone : DateTimeZone|string|int|null = null
Return values
static

toNow()

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
string

toObject()

Get default object representation.

public toObject() : object
Tags
example
var_dump(Carbon::now()->toObject());
Return values
object

toPeriod()

Create a iterable CarbonPeriod object from current date to a given end date (and optional interval).

public toPeriod([DateTimeInterface|Carbon|CarbonImmutable|int|null $end = null ][, int|DateInterval|string|null $interval = null ][, string|null $unit = null ]) : CarbonPeriod
Parameters
$end : DateTimeInterface|Carbon|CarbonImmutable|int|null = null

period end date or recurrences count if int

$interval : int|DateInterval|string|null = null

period default interval or number of the given $unit

$unit : string|null = null

if specified, $interval must be an integer

Return values
CarbonPeriod

toRfc1036String()

Format the instance as RFC1036

public toRfc1036String() : string
Tags
example
echo Carbon::now()->toRfc1036String();
Return values
string

toRfc1123String()

Format the instance as RFC1123

public toRfc1123String() : string
Tags
example
echo Carbon::now()->toRfc1123String();
Return values
string

toRfc2822String()

Format the instance as RFC2822

public toRfc2822String() : string
Tags
example
echo Carbon::now()->toRfc2822String();
Return values
string

toRfc3339String()

Format the instance as RFC3339.

public toRfc3339String([bool $extended = false ]) : string
Parameters
$extended : bool = false
Tags
example
echo Carbon::now()->toRfc3339String() . "\n";
echo Carbon::now()->toRfc3339String(true) . "\n";
Return values
string

toRfc7231String()

Format the instance as RFC7231

public toRfc7231String() : string
Tags
example
echo Carbon::now()->toRfc7231String();
Return values
string

toRfc822String()

Format the instance as RFC822

public toRfc822String() : string
Tags
example
echo Carbon::now()->toRfc822String();
Return values
string

toRfc850String()

Format the instance as RFC850

public toRfc850String() : string
Tags
example
echo Carbon::now()->toRfc850String();
Return values
string

toRssString()

Format the instance as RSS

public toRssString() : string
Tags
example
echo Carbon::now()->toRssString();
Return values
string

toString()

Returns english human-readable complete date string.

public toString() : string
Tags
example
echo Carbon::now()->toString();
Return values
string

toTimeString()

Format the instance as time

public toTimeString([string $unitPrecision = 'second' ]) : string
Parameters
$unitPrecision : string = 'second'
Tags
example
echo Carbon::now()->toTimeString();
Return values
string

toW3cString()

Format the instance as W3C

public toW3cString() : string
Tags
example
echo Carbon::now()->toW3cString();
Return values
string

translate()

Translate using translation string or callback available.

public translate(string $key[, array<string|int, mixed> $parameters = [] ][, string|int|float|null $number = null ][, TranslatorInterface|null $translator = null ][, bool $altNumbers = false ]) : string
Parameters
$key : string

key to find

$parameters : array<string|int, mixed> = []

replacement parameters

$number : string|int|float|null = null

number if plural

$translator : TranslatorInterface|null = null

an optional translator to use

$altNumbers : bool = false

pass true to use alternative numbers

Return values
string

translatedFormat()

Format as ->format() do (using date replacements patterns from https://php.net/manual/en/function.date.php) but translate words whenever possible (months, day names, etc.) using the current locale.

public translatedFormat(string $format) : string
Parameters
$format : string
Return values
string

translateNumber()

Returns the alternative number for a given integer if available in the current locale.

public translateNumber(int $number) : string
Parameters
$number : int
Return values
string

translateTimeString()

Translate a time string from a locale to an other.

public static translateTimeString(string $timeString[, string|null $from = null ][, string|null $to = null ][, int $mode = self::TRANSLATE_ALL ]) : string
Parameters
$timeString : string

date/time/duration string to translate (may also contain English)

$from : string|null = null

input locale of the $timeString parameter (Carbon::getLocale() by default)

$to : string|null = null

output locale of the result returned ("en" by default)

$mode : int = self::TRANSLATE_ALL

specify what to translate with options:

  • self::TRANSLATE_ALL (default)
  • CarbonInterface::TRANSLATE_MONTHS
  • CarbonInterface::TRANSLATE_DAYS
  • CarbonInterface::TRANSLATE_UNITS
  • CarbonInterface::TRANSLATE_MERIDIEM You can use pipe to group: CarbonInterface::TRANSLATE_MONTHS | CarbonInterface::TRANSLATE_DAYS
Return values
string

translateTimeStringTo()

Translate a time string from the current locale (`$date->locale()`) to an other.

public translateTimeStringTo(string $timeString[, string|null $to = null ]) : string
Parameters
$timeString : string

time string to translate

$to : string|null = null

output locale of the result returned ("en" by default)

Return values
string

translateWith()

Translate using translation string or callback available.

public static translateWith(TranslatorInterface $translator, string $key[, array<string|int, mixed> $parameters = [] ][, int|float|null $number = null ]) : string
Parameters
$translator : TranslatorInterface

an optional translator to use

$key : string

key to find

$parameters : array<string|int, mixed> = []

replacement parameters

$number : int|float|null = null

number if plural

Return values
string

tz()

Set the timezone or returns the timezone name if no arguments passed.

public tz([DateTimeZone|string|int|null $value = null ]) : static|string
Parameters
$value : DateTimeZone|string|int|null = null
Return values
static|string

unix()

public unix() : int
Tags
alias

getTimestamp

Returns the UNIX timestamp for the current date.

Return values
int

until()

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
alias

to

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.

Return values
string

useMonthsOverflow()

public static useMonthsOverflow([bool $monthsOverflow = true ]) : void
Parameters
$monthsOverflow : bool = true
Tags
deprecated

To avoid conflict between different third-party libraries, static setters should not be used. You should rather use the ->settings() method. Or you can use method variants: addMonthsWithOverflow/addMonthsNoOverflow, same variants are available for quarters, years, decade, centuries, millennia (singular and plural forms).

see
settings

Indicates if months should be calculated with overflow.

useStrictMode()

public static useStrictMode([bool $strictModeEnabled = true ]) : void
Parameters
$strictModeEnabled : bool = true
Tags
deprecated

To avoid conflict between different third-party libraries, static setters should not be used. You should rather use the ->settings() method.

see
settings

Enable the strict mode (or disable with passing false).

useYearsOverflow()

public static useYearsOverflow([bool $yearsOverflow = true ]) : void
Parameters
$yearsOverflow : bool = true
Tags
deprecated

To avoid conflict between different third-party libraries, static setters should not be used. You should rather use the ->settings() method. Or you can use method variants: addYearsWithOverflow/addYearsNoOverflow, same variants are available for quarters, years, decade, centuries, millennia (singular and plural forms).

see
settings

Indicates if years should be calculated with overflow.

utc()

Set the instance's timezone to UTC.

public utc() : static
Return values
static

utcOffset()

Returns the minutes offset to UTC if no arguments passed, else set the timezone with given minutes shift passed.

public utcOffset([int|null $minuteOffset = null ]) : static|int
Parameters
$minuteOffset : int|null = null
Return values
static|int

valueOf()

Returns the milliseconds timestamps used amongst other by Date javascript objects.

public valueOf() : float
Return values
float

week()

Get/set the week number using given first day of week and first day of year included in the first week. Or use US format if no settings given (Sunday / Jan 6).

public week([int|null $week = null ][, int|null $dayOfWeek = null ][, int|null $dayOfYear = null ]) : int|static
Parameters
$week : int|null = null
$dayOfWeek : int|null = null
$dayOfYear : int|null = null
Return values
int|static

weekday()

Get/set the weekday from 0 (Sunday) to 6 (Saturday).

public weekday([WeekDay|int|null $value = null ]) : static|int
Parameters
$value : WeekDay|int|null = null

new value for weekday if using as setter.

Return values
static|int

weeksInYear()

Get the number of weeks of the current week-year using given first day of week and first day of year included in the first week. Or use US format if no settings given (Sunday / Jan 6).

public weeksInYear([int|null $dayOfWeek = null ][, int|null $dayOfYear = null ]) : int
Parameters
$dayOfWeek : int|null = null

first date of week from 0 (Sunday) to 6 (Saturday)

$dayOfYear : int|null = null

first day of year included in the week #1

Return values
int

weekYear()

Set/get the week number of year using given first day of week and first day of year included in the first week. Or use US format if no settings given (Sunday / Jan 6).

public weekYear([int|null $year = null ][, int|null $dayOfWeek = null ][, int|null $dayOfYear = null ]) : int|static
Parameters
$year : int|null = null

if null, act as a getter, if not null, set the year and return current instance.

$dayOfWeek : int|null = null

first date of week from 0 (Sunday) to 6 (Saturday)

$dayOfYear : int|null = null

first day of year included in the week #1

Return values
int|static

withTestNow()

Temporarily sets a static date to be used within the callback.

public static withTestNow(DateTimeInterface|Closure|static|string|false|null $testNow, callable $callback) : T

Using setTestNow to set the date, executing the callback, then clearing the test instance.

/!\ Use this method for unit tests only.

Parameters
$testNow : DateTimeInterface|Closure|static|string|false|null

real or mock Carbon instance

$callback : callable
Tags
template

T

Return values
T

yesterday()

Create a Carbon instance for yesterday.

public static yesterday([DateTimeZone|string|int|null $timezone = null ]) : static
Parameters
$timezone : DateTimeZone|string|int|null = null
Return values
static

        
On this page

Search results