CarbonInterface
extends
DateTimeInterface, JsonSerializable
in
Common interface for Carbon and CarbonImmutable.
<autodoc generated by composer phpdoc
>
Tags
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
APRIL
public
mixed
APRIL
= 4
AUGUST
public
mixed
AUGUST
= 8
CEIL
public
mixed
CEIL
= 0200
DAYS_PER_WEEK
public
mixed
DAYS_PER_WEEK
= 7
DAYS_PER_YEAR
public
mixed
DAYS_PER_YEAR
= 365
DECEMBER
public
mixed
DECEMBER
= 12
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'
DIFF_ABSOLUTE
Diff syntax options.
public
mixed
DIFF_ABSOLUTE
= 1
DIFF_RELATIVE_AUTO
public
mixed
DIFF_RELATIVE_AUTO
= 0
DIFF_RELATIVE_TO_NOW
public
mixed
DIFF_RELATIVE_TO_NOW
= 2
DIFF_RELATIVE_TO_OTHER
public
mixed
DIFF_RELATIVE_TO_OTHER
= 3
FEBRUARY
public
mixed
FEBRUARY
= 2
FLOOR
public
mixed
FLOOR
= 0100
FRIDAY
public
mixed
FRIDAY
= 5
HOURS_PER_DAY
public
mixed
HOURS_PER_DAY
= 24
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.
JULY
public
mixed
JULY
= 7
JUNE
public
mixed
JUNE
= 6
JUST_NOW
public
mixed
JUST_NOW
= 02
MARCH
public
mixed
MARCH
= 3
MAY
public
mixed
MAY
= 5
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
MINUTES_PER_HOUR
public
mixed
MINUTES_PER_HOUR
= 60
MOCK_DATETIME_FORMAT
Format for converting mocked time, includes microseconds.
public
string
MOCK_DATETIME_FORMAT
= 'Y-m-d H:i:s.u'
MONDAY
public
mixed
MONDAY
= 1
MONTHS_PER_QUARTER
public
mixed
MONTHS_PER_QUARTER
= 3
MONTHS_PER_YEAR
public
mixed
MONTHS_PER_YEAR
= 12
NO_ZERO_DIFF
Diff wording options(expressed in octal).
public
mixed
NO_ZERO_DIFF
= 01
NOVEMBER
public
mixed
NOVEMBER
= 11
OCTOBER
public
mixed
OCTOBER
= 10
ONE_DAY_WORDS
public
mixed
ONE_DAY_WORDS
= 04
QUARTERS_PER_YEAR
public
mixed
QUARTERS_PER_YEAR
= 4
RFC7231_FORMAT
RFC7231 DateTime format.
public
string
RFC7231_FORMAT
= 'D, d M Y H:i:s \\G\\M\\T'
ROUND
public
mixed
ROUND
= 040
SATURDAY
public
mixed
SATURDAY
= 6
SECONDS_PER_MINUTE
public
mixed
SECONDS_PER_MINUTE
= 60
SEPTEMBER
public
mixed
SEPTEMBER
= 9
SEQUENTIAL_PARTS_ONLY
public
mixed
SEQUENTIAL_PARTS_ONLY
= 020
SUNDAY
The day constants.
public
mixed
SUNDAY
= 0
THURSDAY
public
mixed
THURSDAY
= 4
TRANSLATE_ALL
public
mixed
TRANSLATE_ALL
= self::TRANSLATE_MONTHS | self::TRANSLATE_DAYS | self::TRANSLATE_UNITS | self::TRANSLATE_MERIDIEM | self::TRANSLATE_DIFF
TRANSLATE_DAYS
public
mixed
TRANSLATE_DAYS
= 2
TRANSLATE_DIFF
public
mixed
TRANSLATE_DIFF
= 0x10
TRANSLATE_MERIDIEM
public
mixed
TRANSLATE_MERIDIEM
= 8
TRANSLATE_MONTHS
Translate string options.
public
mixed
TRANSLATE_MONTHS
= 1
TRANSLATE_UNITS
public
mixed
TRANSLATE_UNITS
= 4
TUESDAY
public
mixed
TUESDAY
= 2
TWO_DAY_WORDS
public
mixed
TWO_DAY_WORDS
= 010
WEDNESDAY
public
mixed
WEDNESDAY
= 3
WEEK_DAY_AUTO
Special settings to get the start of week from current locale culture.
public
mixed
WEEK_DAY_AUTO
= 'auto'
WEEKS_PER_MONTH
public
mixed
WEEKS_PER_MONTH
= 4
WEEKS_PER_YEAR
public
mixed
WEEKS_PER_YEAR
= 52
YEARS_PER_CENTURY
public
mixed
YEARS_PER_CENTURY
= 100
YEARS_PER_DECADE
public
mixed
YEARS_PER_DECADE
= 10
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
__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
__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
__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
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
__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
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
Return values
staticaddRealUnit()
public
addRealUnit(string $unit[, int|float|null $value = 1 ]) : static
Parameters
- $unit : string
- $value : int|float|null = 1
Tags
Return values
staticaddUnit()
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
staticaddUnitNoOverflow()
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
staticaddUTCUnit()
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
staticago()
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
stringaverage()
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
staticavoidMutation()
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
staticbetween()
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
Return values
boolbetweenExcluded()
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
Return values
boolbetweenIncluded()
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
Return values
boolcalendar()
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
stringcanBeCreatedFromFormat()
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
Return values
boolcarbonize()
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
staticcast()
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
Return values
Tceil()
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
staticceilUnit()
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
staticceilWeek()
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
staticchange()
Similar to native modify() method of DateTime but can handle more grammars.
public
change(string $modifier) : static
Parameters
- $modifier : string
Tags
Return values
staticcleanupDumpProperties()
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
Return values
staticclosest()
Get the closest date from the instance (second-precision).
public
closest(Carbon|DateTimeInterface|mixed $date1, Carbon|DateTimeInterface|mixed $date2) : static
Parameters
Return values
staticcopy()
Get a copy of the instance.
public
copy() : static
Return values
staticcreate()
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
Return values
static|nullcreateFromDate()
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
Return values
staticcreateFromFormat()
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
Return values
static|nullcreateFromIsoFormat()
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
Return values
static|nullcreateFromLocaleFormat()
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
Return values
static|nullcreateFromLocaleIsoFormat()
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
Return values
static|nullcreateFromTime()
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
Return values
staticcreateFromTimestamp()
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
staticcreateFromTimestampMs()
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
staticcreateFromTimestampMsUTC()
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
staticcreateFromTimestampUTC()
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
staticcreateFromTimeString()
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
Return values
staticcreateMidnightDate()
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
Return values
staticcreateSafe()
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
Return values
static|nullcreateStrict()
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
Return values
staticdayOfYear()
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
Return values
static|intdiffAsCarbonInterval()
Get the difference as a CarbonInterval instance.
public
diffAsCarbonInterval([CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ][, array<string|int, mixed> $skip = [] ]) : CarbonInterval
Return relative interval (negative if $absolute flag is not set to true and the given date is before current one).
Parameters
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
- $skip : array<string|int, mixed> = []
Return values
CarbonIntervaldiffAsDateInterval()
Get the difference as a DateInterval instance.
public
diffAsDateInterval([CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ]) : DateInterval
Return relative interval (negative if $absolute flag is not set to true and the given date is before current one).
Parameters
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
Return values
DateIntervaldiffFiltered()
Get the difference by the given interval using a filter closure.
public
diffFiltered(CarbonInterval $ci, Closure $callback[, CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ]) : int
Parameters
- $ci : CarbonInterval
-
An interval to traverse by
- $callback : Closure
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
Return values
intdiffForHumans()
Get the difference in a human readable format in the current locale from current instance to an other instance given (or now if null given).
public
diffForHumans([Carbon|DateTimeInterface|string|array<string|int, mixed>|null $other = null ][, int|array<string|int, mixed> $syntax = null ][, bool $short = false ][, int $parts = 1 ][, int $options = null ]) : string
Parameters
- $other : Carbon|DateTimeInterface|string|array<string|int, mixed>|null = null
-
if array passed, will be used as parameters array, see $syntax below; if null passed, now will be used as comparison reference; if any other type, it will be converted to date and used as reference.
- $syntax : int|array<string|int, mixed> = null
-
if array passed, parameters will be extracted from it, the array may contains: ⦿ 'syntax' entry (see below) ⦿ 'short' entry (see below) ⦿ 'parts' entry (see below) ⦿ 'options' entry (see below) ⦿ 'skip' entry, list of units to skip (array of strings or a single string,
it can be the unit name (singular or plural) or its shortcut
(y, m, w, d, h, min, s, ms, µs). ⦿ 'aUnit' entry, prefer "an hour" over "1 hour" if true ⦿ 'altNumbers' entry, use alternative numbers if available(from the current language if true is passed, from the given language(s)
if array or string is passed) ⦿ 'join' entry determines how to join multiple parts of the string- if $join is a string, it's used as a joiner glue
- if $join is a callable/closure, it get the list of string and should return a string- if $join is an array, the first item will be the default glue, and the second item
will be used instead of the glue for the last item- if $join is true, it will be guessed from the locale ('list' translation file entry)
- if $join is missing, a space will be used as glue ⦿ 'other' entry (see above) ⦿ 'minimumUnit' entry determines the smallest unit of time to display can be long or ` short form of the units, e.g. 'hour' or 'h' (default value: s) ⦿ 'locale' language in which the diff should be output (has no effect if 'translator' key is set) ⦿ 'translator' a custom translator to use to translator the output. if int passed, it adds modifiers: Possible values:- CarbonInterface::DIFF_ABSOLUTE no modifiers
- CarbonInterface::DIFF_RELATIVE_TO_NOW add ago/from now modifier
- CarbonInterface::DIFF_RELATIVE_TO_OTHER add before/after modifier Default value: CarbonInterface::DIFF_ABSOLUTE
- $short : bool = false
-
displays short format of time units
- $parts : int = 1
-
maximum number of parts to display (default value: 1: single unit)
- $options : int = null
-
human diff options
Tags
Return values
stringdiffInDays()
Get the difference in days.
public
diffInDays([CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ][, bool $utc = false ]) : float
Parameters
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
- $utc : bool = false
-
Always convert dates to UTC before comparing (if not set, it will do it only if timezones are different)
Return values
floatdiffInDaysFiltered()
Get the difference in days using a filter closure.
public
diffInDaysFiltered(Closure $callback[, CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ]) : int
Parameters
- $callback : Closure
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
Return values
intdiffInHours()
Get the difference in hours.
public
diffInHours([CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ]) : float
Parameters
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
Return values
floatdiffInHoursFiltered()
Get the difference in hours using a filter closure.
public
diffInHoursFiltered(Closure $callback[, CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ]) : int
Parameters
- $callback : Closure
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
Return values
intdiffInMicroseconds()
Get the difference in microseconds.
public
diffInMicroseconds([CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ]) : float
Parameters
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
Return values
floatdiffInMilliseconds()
Get the difference in milliseconds.
public
diffInMilliseconds([CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ]) : float
Parameters
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
Return values
floatdiffInMinutes()
Get the difference in minutes.
public
diffInMinutes([CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ]) : float
Parameters
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
Return values
floatdiffInMonths()
Get the difference in months.
public
diffInMonths([CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ][, bool $utc = false ]) : float
Parameters
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
- $utc : bool = false
-
Always convert dates to UTC before comparing (if not set, it will do it only if timezones are different)
Return values
floatdiffInQuarters()
Get the difference in quarters.
public
diffInQuarters([CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ][, bool $utc = false ]) : float
Parameters
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
- $utc : bool = false
-
Always convert dates to UTC before comparing (if not set, it will do it only if timezones are different)
Return values
floatdiffInSeconds()
Get the difference in seconds.
public
diffInSeconds([CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ]) : float
Parameters
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
Return values
floatdiffInUnit()
public
diffInUnit(Unit|string $unit[, CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ][, bool $utc = false ]) : float
Parameters
- $unit : Unit|string
-
microsecond, millisecond, second, minute, hour, day, week, month, quarter, year, century, millennium
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
- $utc : bool = false
-
Always convert dates to UTC before comparing (if not set, it will do it only if timezones are different)
Return values
floatdiffInWeekdays()
Get the difference in weekdays.
public
diffInWeekdays([CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ]) : int
Parameters
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
Return values
intdiffInWeekendDays()
Get the difference in weekend days using a filter.
public
diffInWeekendDays([CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ]) : int
Parameters
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
Return values
intdiffInWeeks()
Get the difference in weeks.
public
diffInWeeks([CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ][, bool $utc = false ]) : float
Parameters
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
- $utc : bool = false
-
Always convert dates to UTC before comparing (if not set, it will do it only if timezones are different)
Return values
floatdiffInYears()
Get the difference in years
public
diffInYears([CarbonInterface|DateTimeInterface|string|null $date = null ][, bool $absolute = false ][, bool $utc = false ]) : float
Parameters
- $date : CarbonInterface|DateTimeInterface|string|null = null
- $absolute : bool = false
-
Get the absolute of the difference
- $utc : bool = false
-
Always convert dates to UTC before comparing (if not set, it will do it only if timezones are different)
Return values
floatdisableHumanDiffOption()
public
static disableHumanDiffOption(int $humanDiffOption) : void
Parameters
- $humanDiffOption : int
Tags
enableHumanDiffOption()
public
static enableHumanDiffOption(int $humanDiffOption) : void
Parameters
- $humanDiffOption : int
Tags
endOf()
Modify to end of current given unit.
public
endOf(Unit|string $unit, mixed ...$params) : static
Parameters
- $unit : Unit|string
- $params : mixed
Tags
Return values
staticendOfCentury()
Resets the date to end of the century and time to 23:59:59.999999
public
endOfCentury() : static
Tags
Return values
staticendOfDay()
Resets the time to 23:59:59.999999 end of day
public
endOfDay() : static
Tags
Return values
staticendOfDecade()
Resets the date to end of the decade and time to 23:59:59.999999
public
endOfDecade() : static
Tags
Return values
staticendOfHour()
Modify to end of current hour, minutes and seconds become 59
public
endOfHour() : static
Tags
Return values
staticendOfMillennium()
Resets the date to end of the millennium and time to 23:59:59.999999
public
endOfMillennium() : static
Tags
Return values
staticendOfMillisecond()
Modify to end of current millisecond, microseconds such as 12345 become 123999
public
endOfMillisecond() : static
Tags
Return values
staticendOfMinute()
Modify to end of current minute, seconds become 59
public
endOfMinute() : static
Tags
Return values
staticendOfMonth()
Resets the date to end of the month and time to 23:59:59.999999
public
endOfMonth() : static
Tags
Return values
staticendOfQuarter()
Resets the date to end of the quarter and time to 23:59:59.999999
public
endOfQuarter() : static
Tags
Return values
staticendOfSecond()
Modify to end of current second, microseconds become 999999
public
endOfSecond() : static
Tags
Return values
staticendOfWeek()
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
Return values
staticendOfYear()
Resets the date to end of the year and time to 23:59:59.999999
public
endOfYear() : static
Tags
Return values
staticeq()
Determines if the instance is equal to another
public
eq(DateTimeInterface|string $date) : bool
Parameters
- $date : DateTimeInterface|string
Tags
Return values
boolequalTo()
Determines if the instance is equal to another
public
equalTo(DateTimeInterface|string $date) : bool
Parameters
- $date : DateTimeInterface|string
Tags
Return values
boolexecuteWithLocale()
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
Return values
staticfirstOfMonth()
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
staticfirstOfQuarter()
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
staticfirstOfYear()
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
staticfloor()
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
staticfloorUnit()
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
staticfloorWeek()
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
staticfrom()
public
from([Carbon|DateTimeInterface|string|array<string|int, mixed>|null $other = null ][, int|array<string|int, mixed> $syntax = null ][, bool $short = false ][, int $parts = 1 ][, int $options = null ]) : string
Parameters
- $other : Carbon|DateTimeInterface|string|array<string|int, mixed>|null = null
-
if array passed, will be used as parameters array, see $syntax below; if null passed, now will be used as comparison reference; if any other type, it will be converted to date and used as reference.
- $syntax : int|array<string|int, mixed> = null
-
if array passed, parameters will be extracted from it, the array may contains:
- 'syntax' entry (see below)
- 'short' entry (see below)
- 'parts' entry (see below)
- 'options' entry (see below)
- 'join' entry determines how to join multiple parts of the string
- if $join is a string, it's used as a joiner glue
- if $join is a callable/closure, it get the list of string and should return a string- if $join is an array, the first item will be the default glue, and the second item
will be used instead of the glue for the last item- if $join is true, it will be guessed from the locale ('list' translation file entry)
- if $join is missing, a space will be used as glue - 'other' entry (see above) if int passed, it add modifiers: Possible values:
- CarbonInterface::DIFF_ABSOLUTE no modifiers
- CarbonInterface::DIFF_RELATIVE_TO_NOW add ago/from now modifier
- CarbonInterface::DIFF_RELATIVE_TO_OTHER add before/after modifier Default value: CarbonInterface::DIFF_ABSOLUTE
- $short : bool = false
-
displays short format of time units
- $parts : int = 1
-
maximum number of parts to display (default value: 1: single unit)
- $options : int = null
-
human diff options
Tags
Return values
stringfromNow()
Get the difference in a human readable format in the current locale from current instance to now.
public
fromNow([int|array<string|int, mixed> $syntax = null ][, bool $short = false ][, int $parts = 1 ][, int $options = null ]) : string
Parameters
- $syntax : int|array<string|int, mixed> = null
-
if array passed, parameters will be extracted from it, the array may contains:
- 'syntax' entry (see below)
- 'short' entry (see below)
- 'parts' entry (see below)
- 'options' entry (see below)
- 'join' entry determines how to join multiple parts of the string
- if $join is a string, it's used as a joiner glue
- if $join is a callable/closure, it get the list of string and should return a string- if $join is an array, the first item will be the default glue, and the second item
will be used instead of the glue for the last item- if $join is true, it will be guessed from the locale ('list' translation file entry)
- if $join is missing, a space will be used as glue if int passed, it add modifiers: Possible values: - CarbonInterface::DIFF_ABSOLUTE no modifiers
- CarbonInterface::DIFF_RELATIVE_TO_NOW add ago/from now modifier
- CarbonInterface::DIFF_RELATIVE_TO_OTHER add before/after modifier Default value: CarbonInterface::DIFF_ABSOLUTE
- $short : bool = false
-
displays short format of time units
- $parts : int = 1
-
maximum number of parts to display (default value: 1: single unit)
- $options : int = null
-
human diff options
Return values
stringfromSerialized()
Create an instance from a serialized string.
public
static fromSerialized(string $value) : static
Parameters
- $value : string
Tags
Return values
staticgenericMacro()
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
get()
Get a part of the Carbon object.
public
get(Unit|string $name) : string|int|bool|DateTimeZone
Parameters
- $name : Unit|string
Tags
Return values
string|int|bool|DateTimeZonegetAltNumber()
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
stringgetAvailableLocales()
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>getClock()
public
getClock() : WrapperClock|null
Return values
WrapperClock|nullgetDays()
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
intgetFallbackLocale()
Get the fallback locale.
public
static getFallbackLocale() : string|null
Tags
Return values
string|nullgetFormatsToIsoReplacements()
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
intgetIsoFormats()
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>|falsegetLocale()
Get the current translator locale.
public
static getLocale() : string
Return values
stringgetLocalMacro()
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|nullgetLocalTranslator()
Get the translator of the current instance or the default if none set.
public
getLocalTranslator() : TranslatorInterface
Return values
TranslatorInterfacegetMacro()
Get the raw callable macro registered globally for a given name.
public
static getMacro(string $name) : callable|null
Parameters
- $name : string
Return values
callable|nullgetMidDayAt()
get midday/noon hour
public
static getMidDayAt() : int
Return values
intgetOffsetString()
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
stringgetPaddedUnit()
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
stringgetPreciseTimestamp()
Returns a timestamp rounded with the given precision (6 by default).
public
getPreciseTimestamp([int $precision = 6 ]) : float
Parameters
- $precision : int = 6
Tags
Return values
floatgetSettings()
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
stringgetTimestampMs()
Returns the timestamp with millisecond precision.
public
getTimestampMs() : int
Return values
intgetTranslatedDayName()
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
stringgetTranslatedMinDayName()
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
stringgetTranslatedMonthName()
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
stringgetTranslatedShortDayName()
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
stringgetTranslatedShortMonthName()
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
stringgetTranslationMessage()
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
stringgetTranslationMessageWith()
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|nullgetTranslator()
Initialize the default translator instance if necessary.
public
static getTranslator() : TranslatorInterface
Return values
TranslatorInterfacegetWeekendDays()
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
intgetWeekStartsAt()
Get the first day of week.
public
static getWeekStartsAt([string|null $locale = null ]) : int
Parameters
- $locale : string|null = null
Return values
intgreaterThan()
Determines if the instance is greater (after) than another
public
greaterThan(DateTimeInterface|string $date) : bool
Parameters
- $date : DateTimeInterface|string
Tags
Return values
boolgreaterThanOrEqualTo()
Determines if the instance is greater (after) than or equal to another
public
greaterThanOrEqualTo(DateTimeInterface|string $date) : bool
Parameters
- $date : DateTimeInterface|string
Tags
Return values
boolgt()
Determines if the instance is greater (after) than another
public
gt(DateTimeInterface|string $date) : bool
Parameters
- $date : DateTimeInterface|string
Tags
Return values
boolgte()
Determines if the instance is greater (after) than or equal to another
public
gte(DateTimeInterface|string $date) : bool
Parameters
- $date : DateTimeInterface|string
Tags
Return values
boolhasFormat()
Checks if the (date)time string is in a given format.
public
static hasFormat(string $date, string $format) : bool
Parameters
- $date : string
- $format : string
Tags
Return values
boolhasFormatWithModifiers()
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
Return values
boolhasLocalMacro()
Checks if macro is registered globally or locally.
public
hasLocalMacro(string $name) : bool
Parameters
- $name : string
Return values
boolhasLocalTranslator()
Return true if the current instance has its own translator.
public
hasLocalTranslator() : bool
Return values
boolhasMacro()
Checks if macro is registered globally.
public
static hasMacro(string $name) : bool
Parameters
- $name : string
Return values
boolhasRelativeKeywords()
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
staticis()
Returns true if the current date matches the given string.
public
is(string $tester) : bool
Parameters
- $tester : string
-
day name, month name, hour, date, etc. as string
Tags
Return values
boolisAfter()
Determines if the instance is greater (after) than another
public
isAfter(DateTimeInterface|string $date) : bool
Parameters
- $date : DateTimeInterface|string
Tags
Return values
boolisBefore()
Determines if the instance is less (before) than another
public
isBefore(DateTimeInterface|string $date) : bool
Parameters
- $date : DateTimeInterface|string
Tags
Return values
boolisBetween()
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
Return values
boolisBirthday()
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
Return values
boolisCurrentUnit()
Determines if the instance is in the current unit given.
public
isCurrentUnit(string $unit) : bool
Parameters
- $unit : string
-
The unit to test.
Tags
Return values
boolisDayOfWeek()
Checks if this day is a specific day of the week.
public
isDayOfWeek(int|string $dayOfWeek) : bool
Parameters
- $dayOfWeek : int|string
Tags
Return values
boolisEndOfCentury()
Determines if the instance is end of century (last day by default but interval can be customized).
public
isEndOfCentury([Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ]) : bool
Parameters
- $interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
Return values
boolisEndOfDay()
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
Return values
boolisEndOfDecade()
Determines if the instance is end of decade (last day by default but interval can be customized).
public
isEndOfDecade([Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ]) : bool
Parameters
- $interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
Return values
boolisEndOfHour()
Determines if the instance is end of hour (last microsecond by default but interval can be customized).
public
isEndOfHour([Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ]) : bool
Parameters
- $interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
Return values
boolisEndOfMillennium()
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
boolisEndOfMillisecond()
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
boolisEndOfMinute()
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
boolisEndOfMonth()
Determines if the instance is end of month (last day by default but interval can be customized).
public
isEndOfMonth([Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ]) : bool
Parameters
- $interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
Return values
boolisEndOfQuarter()
Determines if the instance is end of quarter (last day by default but interval can be customized).
public
isEndOfQuarter([Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ]) : bool
Parameters
- $interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
Return values
boolisEndOfSecond()
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
boolisEndOfTime()
Returns true if the date was created using CarbonImmutable::endOfTime()
public
isEndOfTime() : bool
Return values
boolisEndOfUnit()
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
Return values
boolisEndOfWeek()
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
Return values
boolisEndOfYear()
Determines if the instance is end of year (last day by default but interval can be customized).
public
isEndOfYear([Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ]) : bool
Parameters
- $interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
Return values
boolisFuture()
Determines if the instance is in the future, ie. greater (after) than now.
public
isFuture() : bool
Tags
Return values
boolisImmutable()
Returns true if the current class/instance is immutable.
public
static isImmutable() : bool
Return values
boolisLastOfMonth()
Check if today is the last day of the Month
public
isLastOfMonth() : bool
Tags
Return values
boolisLeapYear()
Determines if the instance is a leap year.
public
isLeapYear() : bool
Tags
Return values
boolisLongIsoYear()
Determines if the instance is a long year (using ISO 8601 year).
public
isLongIsoYear() : bool
Tags
Return values
boolisLongYear()
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
Return values
boolisMidday()
Check if the instance is midday.
public
isMidday() : bool
Tags
Return values
boolisMidnight()
Check if the instance is start of day / midnight.
public
isMidnight() : bool
Tags
Return values
boolisModifiableUnit()
Returns true if a property can be changed via setter.
public
static isModifiableUnit(string $unit) : bool
Parameters
- $unit : string
Return values
boolisMutable()
Returns true if the current class/instance is mutable.
public
static isMutable() : bool
Return values
boolisoFormat()
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
stringisoWeek()
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|staticisoWeekday()
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|intisoWeeksInYear()
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
intisoWeekYear()
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|staticisPast()
Determines if the instance is in the past, ie. less (before) than now.
public
isPast() : bool
Tags
Return values
boolisSameAs()
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
Return values
boolisSameMonth()
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
Return values
boolisSameQuarter()
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
Return values
boolisSameUnit()
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
Return values
boolisStartOfCentury()
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
boolisStartOfDay()
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
Return values
boolisStartOfDecade()
Determines if the instance is start of decade (first day by default but interval can be customized).
public
isStartOfDecade([Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ]) : bool
Parameters
- $interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
Return values
boolisStartOfHour()
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
boolisStartOfMillennium()
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
boolisStartOfMillisecond()
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
boolisStartOfMinute()
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
boolisStartOfMonth()
Determines if the instance is start of month (first day by default but interval can be customized).
public
isStartOfMonth([Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ]) : bool
Parameters
- $interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
Return values
boolisStartOfQuarter()
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
boolisStartOfSecond()
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
boolisStartOfTime()
Returns true if the date was created using CarbonImmutable::startOfTime()
public
isStartOfTime() : bool
Return values
boolisStartOfUnit()
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
Return values
boolisStartOfWeek()
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
Return values
boolisStartOfYear()
Determines if the instance is start of year (first day by default but interval can be customized).
public
isStartOfYear([Unit|DateInterval|Closure|CarbonConverterInterface|string|null $interval = null ]) : bool
Parameters
- $interval : Unit|DateInterval|Closure|CarbonConverterInterface|string|null = null
Return values
boolisStrictModeEnabled()
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
boolisToday()
Determines if the instance is today.
public
isToday() : bool
Tags
Return values
boolisTomorrow()
Determines if the instance is tomorrow.
public
isTomorrow() : bool
Tags
Return values
boolisWeekday()
Determines if the instance is a weekday.
public
isWeekday() : bool
Tags
Return values
boolisWeekend()
Determines if the instance is a weekend day.
public
isWeekend() : bool
Tags
Return values
boolisYesterday()
Determines if the instance is yesterday.
public
isYesterday() : bool
Tags
Return values
booljsonSerialize()
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
staticlastOfQuarter()
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
staticlastOfYear()
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
staticlessThan()
Determines if the instance is less (before) than another
public
lessThan(DateTimeInterface|string $date) : bool
Parameters
- $date : DateTimeInterface|string
Tags
Return values
boollessThanOrEqualTo()
Determines if the instance is less (before) or equal to another
public
lessThanOrEqualTo(DateTimeInterface|string $date) : bool
Parameters
- $date : DateTimeInterface|string
Tags
Return values
boollocale()
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|stringlocaleHasDiffOneDayWords()
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
boollocaleHasDiffSyntax()
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
boollocaleHasDiffTwoDayWords()
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
boollocaleHasPeriodSyntax()
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
boollocaleHasShortUnits()
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
boollt()
Determines if the instance is less (before) than another
public
lt(DateTimeInterface|string $date) : bool
Parameters
- $date : DateTimeInterface|string
Tags
Return values
boollte()
Determines if the instance is less (before) or equal to another
public
lte(DateTimeInterface|string $date) : bool
Parameters
- $date : DateTimeInterface|string
Tags
Return values
boolmacro()
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
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
Return values
static|nullmax()
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
staticmaximum()
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
Return values
staticmeridiem()
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
stringmidDay()
Modify to midday, default to self::$midDayAt
public
midDay() : static
Return values
staticmin()
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
staticminimum()
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
Return values
staticmixin()
Mix another object into the class.
public
static mixin(object|string $mixin) : void
Parameters
- $mixin : object|string
Tags
modify()
Calls \DateTime::modify if mutable or \DateTimeImmutable::modify else.
public
modify(mixed $modify) : static
Parameters
- $modify : mixed
Tags
Return values
staticne()
Determines if the instance is not equal to another
public
ne(DateTimeInterface|string $date) : bool
Parameters
- $date : DateTimeInterface|string
Tags
Return values
boolnext()
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
staticnextWeekday()
Go forward to the next weekday.
public
nextWeekday() : static
Return values
staticnextWeekendDay()
Go forward to the next weekend day.
public
nextWeekendDay() : static
Return values
staticnotEqualTo()
Determines if the instance is not equal to another
public
notEqualTo(DateTimeInterface|string $date) : bool
Parameters
- $date : DateTimeInterface|string
Tags
Return values
boolnow()
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
staticnowWithSameTz()
Returns a present instance in the same timezone.
public
nowWithSameTz() : static
Return values
staticnthOfMonth()
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
stringparse()
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
Return values
staticparseFromLocale()
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
Return values
staticpluralUnit()
Returns standardized plural of a given singular/plural unit name (in English).
public
static pluralUnit(string $unit) : string
Parameters
- $unit : string
Return values
stringprevious()
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
staticpreviousWeekday()
Go backward to the previous weekday.
public
previousWeekday() : static
Return values
staticpreviousWeekendDay()
Go backward to the previous weekend day.
public
previousWeekendDay() : static
Return values
staticrange()
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
CarbonPeriodrawAdd()
Call native PHP DateTime/DateTimeImmutable add() method.
public
rawAdd(DateInterval $interval) : static
Parameters
- $interval : DateInterval
Return values
staticrawCreateFromFormat()
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
Return values
static|nullrawFormat()
public
rawFormat(string $format) : string
Parameters
- $format : string
Tags
Return values
stringrawParse()
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
Return values
staticrawSub()
Call native PHP DateTime/DateTimeImmutable sub() method.
public
rawSub(DateInterval $interval) : static
Parameters
- $interval : DateInterval
Return values
staticresetMacros()
Remove all macros and generic macros.
public
static resetMacros() : void
resetMonthsOverflow()
public
static resetMonthsOverflow() : void
Tags
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
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
staticroundUnit()
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
staticroundWeek()
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
staticsecondsSinceMidnight()
The number of seconds since midnight.
public
secondsSinceMidnight() : float
Return values
floatsecondsUntilEndOfDay()
The number of seconds until 23:59:59.
public
secondsUntilEndOfDay() : float
Return values
floatserialize()
Return a serialized string of the instance.
public
serialize() : string
Return values
stringserializeUsing()
public
static serializeUsing(callable|string|null $format) : void
Parameters
- $format : callable|string|null
Tags
set()
Set a part of the Carbon object.
public
set(Unit|array<string|int, mixed>|string $name[, DateTimeZone|Month|string|int|float|null $value = null ]) : $this
Parameters
- $name : Unit|array<string|int, mixed>|string
- $value : DateTimeZone|Month|string|int|float|null = null
Tags
Return values
$thissetDate()
Set the date with gregorian year, month and day numbers.
public
setDate(int $year, int $month, int $day) : static
Parameters
- $year : int
- $month : int
- $day : int
Tags
Return values
staticsetDateFrom()
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
staticsetDateTime()
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
staticsetDateTimeFrom()
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
staticsetDaysFromStartOfWeek()
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
staticsetFallbackLocale()
Set the fallback locale.
public
static setFallbackLocale(string $locale) : void
Parameters
- $locale : string
Tags
setHumanDiffOptions()
public
static setHumanDiffOptions(int $humanDiffOptions) : void
Parameters
- $humanDiffOptions : int
Tags
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
Return values
staticsetLocale()
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
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
Return values
staticsetTimeFrom()
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
staticsetTimeFromTimeString()
Set the time by time string.
public
setTimeFromTimeString(string $time) : static
Parameters
- $time : string
Return values
staticsetTimestamp()
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
staticsetTimezone()
Set the instance's timezone from a string or object.
public
setTimezone(DateTimeZone|string|int $timeZone) : static
Parameters
- $timeZone : DateTimeZone|string|int
Return values
staticsettings()
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|staticsetToStringFormat()
public
static setToStringFormat(string|Closure|null $format) : void
Parameters
- $format : string|Closure|null
Tags
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
staticsetUnitNoOverflow()
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
staticsetWeekendDays()
public
static setWeekendDays(array<string|int, mixed> $days) : void
Parameters
- $days : array<string|int, mixed>
Tags
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
staticshouldOverflowMonths()
Get the month overflow global behavior (can be overridden in specific instances).
public
static shouldOverflowMonths() : bool
Return values
boolshouldOverflowYears()
Get the month overflow global behavior (can be overridden in specific instances).
public
static shouldOverflowYears() : bool
Return values
boolsince()
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
singularUnit()
Returns standardized singular of a given singular/plural unit name (in English).
public
static singularUnit(string $unit) : string
Parameters
- $unit : string
Return values
stringsleep()
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
Return values
staticstartOfCentury()
Resets the date to the first day of the century and the time to 00:00:00
public
startOfCentury() : static
Tags
Return values
staticstartOfDay()
Resets the time to 00:00:00 start of day
public
startOfDay() : static
Tags
Return values
staticstartOfDecade()
Resets the date to the first day of the decade and the time to 00:00:00
public
startOfDecade() : static
Tags
Return values
staticstartOfHour()
Modify to start of current hour, minutes and seconds become 0
public
startOfHour() : static
Tags
Return values
staticstartOfMillennium()
Resets the date to the first day of the millennium and the time to 00:00:00
public
startOfMillennium() : static
Tags
Return values
staticstartOfMillisecond()
Modify to start of current millisecond, microseconds such as 12345 become 123000
public
startOfMillisecond() : static
Tags
Return values
staticstartOfMinute()
Modify to start of current minute, seconds become 0
public
startOfMinute() : static
Tags
Return values
staticstartOfMonth()
Resets the date to the first day of the month and the time to 00:00:00
public
startOfMonth() : static
Tags
Return values
staticstartOfQuarter()
Resets the date to the first day of the quarter and the time to 00:00:00
public
startOfQuarter() : static
Tags
Return values
staticstartOfSecond()
Modify to start of current second, microseconds become 0
public
startOfSecond() : static
Tags
Return values
staticstartOfWeek()
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
Return values
staticstartOfYear()
Resets the date to the first day of the year and the time to 00:00:00
public
startOfYear() : static
Tags
Return values
staticsub()
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
Return values
staticsubRealUnit()
public
subRealUnit(string $unit[, int $value = 1 ]) : static
Parameters
- $unit : string
- $value : int = 1
Tags
Return values
staticsubtract()
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
Return values
staticsubUnit()
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
staticsubUnitNoOverflow()
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
staticsubUTCUnit()
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
statictimespan()
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
stringtimestamp()
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
statictimezone()
public
timezone(DateTimeZone|string|int $value) : static
Parameters
- $value : DateTimeZone|string|int
Tags
Return values
staticto()
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
stringtoArray()
Get default array representation.
public
toArray() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>toAtomString()
Format the instance as ATOM
public
toAtomString() : string
Tags
Return values
stringtoCookieString()
Format the instance as COOKIE
public
toCookieString() : string
Tags
Return values
stringtoDate()
public
toDate() : DateTime
Tags
Return values
DateTimetoDateString()
Format the instance as date
public
toDateString() : string
Tags
Return values
stringtoDateTime()
Return native DateTime PHP object matching the current instance.
public
toDateTime() : DateTime
Tags
Return values
DateTimetoDateTimeImmutable()
Return native toDateTimeImmutable PHP object matching the current instance.
public
toDateTimeImmutable() : DateTimeImmutable
Tags
Return values
DateTimeImmutabletoDateTimeLocalString()
Format the instance as date and time T-separated with no timezone
public
toDateTimeLocalString([string $unitPrecision = 'second' ]) : string
Parameters
- $unitPrecision : string = 'second'
Tags
Return values
stringtoDateTimeString()
Format the instance as date and time
public
toDateTimeString([string $unitPrecision = 'second' ]) : string
Parameters
- $unitPrecision : string = 'second'
Tags
Return values
stringtoday()
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
statictoDayDateTimeString()
Format the instance with day, date and time
public
toDayDateTimeString() : string
Tags
Return values
stringtoFormattedDateString()
Format the instance as a readable date
public
toFormattedDateString() : string
Tags
Return values
stringtoFormattedDayDateString()
Format the instance with the day, and a readable date
public
toFormattedDayDateString() : string
Tags
Return values
stringtoImmutable()
Return a immutable copy of the instance.
public
toImmutable() : CarbonImmutable
Return values
CarbonImmutabletoIso8601String()
Format the instance as ISO8601
public
toIso8601String() : string
Tags
Return values
stringtoIso8601ZuluString()
Convert the instance to UTC and return as Zulu ISO8601
public
toIso8601ZuluString([string $unitPrecision = 'second' ]) : string
Parameters
- $unitPrecision : string = 'second'
Tags
Return values
stringtoISOString()
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
Return values
string|nulltoJSON()
Return the ISO-8601 string (ex: 1977-04-22T06:00:00Z) with UTC timezone.
public
toJSON() : string|null
Tags
Return values
string|nulltomorrow()
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
statictoMutable()
Return a mutable copy of the instance.
public
toMutable() : Carbon
Return values
CarbontoNow()
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
stringtoObject()
Get default object representation.
public
toObject() : object
Tags
Return values
objecttoPeriod()
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
CarbonPeriodtoRfc1036String()
Format the instance as RFC1036
public
toRfc1036String() : string
Tags
Return values
stringtoRfc1123String()
Format the instance as RFC1123
public
toRfc1123String() : string
Tags
Return values
stringtoRfc2822String()
Format the instance as RFC2822
public
toRfc2822String() : string
Tags
Return values
stringtoRfc3339String()
Format the instance as RFC3339.
public
toRfc3339String([bool $extended = false ]) : string
Parameters
- $extended : bool = false
Tags
Return values
stringtoRfc7231String()
Format the instance as RFC7231
public
toRfc7231String() : string
Tags
Return values
stringtoRfc822String()
Format the instance as RFC822
public
toRfc822String() : string
Tags
Return values
stringtoRfc850String()
Format the instance as RFC850
public
toRfc850String() : string
Tags
Return values
stringtoRssString()
Format the instance as RSS
public
toRssString() : string
Tags
Return values
stringtoString()
Returns english human-readable complete date string.
public
toString() : string
Tags
Return values
stringtoTimeString()
Format the instance as time
public
toTimeString([string $unitPrecision = 'second' ]) : string
Parameters
- $unitPrecision : string = 'second'
Tags
Return values
stringtoW3cString()
Format the instance as W3C
public
toW3cString() : string
Tags
Return values
stringtranslate()
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
stringtranslatedFormat()
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
stringtranslateNumber()
Returns the alternative number for a given integer if available in the current locale.
public
translateNumber(int $number) : string
Parameters
- $number : int
Return values
stringtranslateTimeString()
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
stringtranslateTimeStringTo()
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
stringtranslateWith()
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
stringtz()
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|stringunix()
public
unix() : int
Tags
Return values
intuntil()
public
until([Carbon|DateTimeInterface|string|array<string|int, mixed>|null $other = null ][, int|array<string|int, mixed> $syntax = null ][, bool $short = false ][, int $parts = 1 ][, int $options = null ]) : string
Parameters
- $other : Carbon|DateTimeInterface|string|array<string|int, mixed>|null = null
-
if array passed, will be used as parameters array, see $syntax below; if null passed, now will be used as comparison reference; if any other type, it will be converted to date and used as reference.
- $syntax : int|array<string|int, mixed> = null
-
if array passed, parameters will be extracted from it, the array may contains:
- 'syntax' entry (see below)
- 'short' entry (see below)
- 'parts' entry (see below)
- 'options' entry (see below)
- 'join' entry determines how to join multiple parts of the string
- if $join is a string, it's used as a joiner glue
- if $join is a callable/closure, it get the list of string and should return a string- if $join is an array, the first item will be the default glue, and the second item
will be used instead of the glue for the last item- if $join is true, it will be guessed from the locale ('list' translation file entry)
- if $join is missing, a space will be used as glue - 'other' entry (see above) if int passed, it add modifiers: Possible values:
- CarbonInterface::DIFF_ABSOLUTE no modifiers
- CarbonInterface::DIFF_RELATIVE_TO_NOW add ago/from now modifier
- CarbonInterface::DIFF_RELATIVE_TO_OTHER add before/after modifier Default value: CarbonInterface::DIFF_ABSOLUTE
- $short : bool = false
-
displays short format of time units
- $parts : int = 1
-
maximum number of parts to display (default value: 1: single unit)
- $options : int = null
-
human diff options
Tags
Return values
stringuseMonthsOverflow()
public
static useMonthsOverflow([bool $monthsOverflow = true ]) : void
Parameters
- $monthsOverflow : bool = true
Tags
useStrictMode()
public
static useStrictMode([bool $strictModeEnabled = true ]) : void
Parameters
- $strictModeEnabled : bool = true
Tags
useYearsOverflow()
public
static useYearsOverflow([bool $yearsOverflow = true ]) : void
Parameters
- $yearsOverflow : bool = true
Tags
utc()
Set the instance's timezone to UTC.
public
utc() : static
Return values
staticutcOffset()
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|intvalueOf()
Returns the milliseconds timestamps used amongst other by Date javascript objects.
public
valueOf() : float
Return values
floatweek()
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|staticweekday()
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|intweeksInYear()
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
intweekYear()
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|staticwithTestNow()
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
Return values
Tyesterday()
Create a Carbon instance for yesterday.
public
static yesterday([DateTimeZone|string|int|null $timezone = null ]) : static
Parameters
- $timezone : DateTimeZone|string|int|null = null