Carbon
extends Carbon
in package
implements
JsonSerializable
Uses
Macroable
A simple API extension for DateTime
Interfaces, Classes and Traits
Table of Contents
- DAYS_PER_WEEK = 7
- DEFAULT_TO_STRING_FORMAT = 'Y-m-d H:i:s'
- Default format to use for __toString method when type juggling occurs.
- DIFF_RELATIVE_TO_NOW = 'relative-to-now'
- DIFF_RELATIVE_TO_OTHER = 'relative-to-other'
- FRIDAY = 5
- HOURS_PER_DAY = 24
- JUST_NOW = 02
- MICROSECONDS_PER_MILLISECOND = 1000
- MICROSECONDS_PER_SECOND = 1000000
- 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
- ONE_DAY_WORDS = 04
- RFC7231_FORMAT = 'D, d M Y H:i:s \G\M\T'
- RFC7231 DateTime format.
- SATURDAY = 6
- SECONDS_PER_MINUTE = 60
- SUNDAY = 0
- The day constants.
- THURSDAY = 4
- TUESDAY = 2
- TWO_DAY_WORDS = 010
- WEDNESDAY = 3
- 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.
- $age : int
- $day : int
- $dayOfWeek : int
- $dayOfWeekIso : int
- $dayOfYear : int
- $daysInMonth : int
- $dst : bool
- $englishDayOfWeek : string
- $englishMonth : string
- $hour : int
- $local : bool
- $localeDayOfWeek : string
- $localeMonth : string
- $micro : int
- $minute : int
- $month : int
- $offset : int
- $offsetHours : int
- $PHPIntSize : int
- Customizable PHP_INT_SIZE override.
- $quarter : int
- $second : int
- $shortEnglishDayOfWeek : string
- $shortEnglishMonth : string
- $shortLocaleDayOfWeek : string
- $shortLocaleMonth : string
- $timestamp : int
- $timezone : DateTimeZone
- $timezoneName : string
- $tz : DateTimeZone
- $tzName : string
- $utc : bool
- $weekNumberInMonth : int
- $weekOfMonth : int
- $weekOfYear : int
- $year : int
- $yearIso : int
- $compareYearWithMonth : bool
- Indicates if years are compared with month by default so isSameMonth and isSameQuarter have $ofSameYear set to true by default.
- $days : array<string|int, mixed>
- Names of days of the week.
- $humanDiffOptions : int
- Options for diffForHumans().
- $lastErrors : array<string|int, mixed>
- The errors that can occur.
- $localMacros : array<string|int, mixed>
- The registered string macros.
- $macros : array<string|int, mixed>
- The registered string macros.
- $microsecondsFallback : bool
- Add microseconds to now on PHP < 7.1 and 7.1.3. true by default.
- $midDayAt : int
- Midday/noon hour.
- $monthsOverflow : bool
- Indicates if months should be calculated with overflow.
- $regexFormats : array<string|int, mixed>
- Format regex patterns.
- $serializer : callable|null
- The custom Carbon JSON serializer.
- $testNow : Carbon
- A test Carbon instance to be returned when now instances are created.
- $toStringFormat : string
- Format to use for __toString method when type juggling occurs.
- $translator : TranslatorInterface
- A translator to ... er ... translate stuff.
- $utf8 : bool
- Will UTF8 encoding be used to print localized date/time ?
- $weekendDays : array<string|int, mixed>
- Days of weekend.
- $weekEndsAt : int
- Last day of week.
- $weekStartsAt : int
- First day of week.
- $yearsOverflow : bool
- Indicates if years should be calculated with overflow.
- __call() : mixed
- Dynamically handle calls to the class.
- __callStatic() : mixed
- Dynamically handle calls to the class.
- __construct() : mixed
- Create a new Carbon instance.
- __debugInfo() : array<string|int, mixed>
- Show truthy properties on var_dump().
- __get() : string|int|bool|DateTimeZone
- 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.
- __toString() : string
- Format the instance as a string using the set format
- addCenturies() : static
- Add centuries to the instance. Positive $value travels forward while negative $value travels into the past.
- addCentury() : static
- Add a century to the instance
- addDay() : static
- Add a day to the instance
- addDays() : static
- Add days to the instance. Positive $value travels forward while negative $value travels into the past.
- addHour() : static
- Add an hour to the instance.
- addHours() : static
- Add hours to the instance. Positive $value travels forward while negative $value travels into the past.
- addMinute() : static
- Add a minute to the instance.
- addMinutes() : static
- Add minutes to the instance using timestamp. Positive $value travels forward while negative $value travels into the past.
- addMonth() : static
- Add a month to the instance
- addMonthNoOverflow() : static
- Add a month with no overflow to the instance
- addMonths() : static
- Add months to the instance. Positive $value travels forward while negative $value travels into the past.
- addMonthsNoOverflow() : static
- Add months without overflowing to the instance. Positive $value travels forward while negative $value travels into the past.
- addMonthsWithOverflow() : static
- Add months to the instance. Positive $value travels forward while negative $value travels into the past.
- addMonthWithOverflow() : static
- Add a month to the instance
- addQuarter() : static
- Add a quarter to the instance
- addQuarters() : static
- Add quarters to the instance. Positive $value travels forward while negative $value travels into the past.
- addRealHour() : static
- Add an hour to the instance using timestamp.
- addRealHours() : static
- Add hours to the instance using timestamp. Positive $value travels forward while negative $value travels into the past.
- addRealMinute() : static
- Add a minute to the instance using timestamp.
- addRealMinutes() : static
- Add minutes to the instance using timestamp. Positive $value travels forward while negative $value travels into the past.
- addRealSecond() : static
- Add a second to the instance using timestamp.
- addRealSeconds() : static
- Add seconds to the instance using timestamp. Positive $value travels forward while negative $value travels into the past.
- addSecond() : static
- Add a second to the instance.
- addSeconds() : static
- Add seconds to the instance. Positive $value travels forward while negative $value travels into the past.
- addWeek() : static
- Add a week to the instance
- addWeekday() : static
- Add a weekday to the instance
- addWeekdays() : static
- Add weekdays to the instance. Positive $value travels forward while negative $value travels into the past.
- addWeeks() : static
- Add weeks to the instance. Positive $value travels forward while negative $value travels into the past.
- addYear() : static
- Add a year to the instance
- addYearNoOverflow() : static
- Add year with overflow months set to false
- addYears() : static
- Add years to the instance. Positive $value travel forward while negative $value travel into the past.
- addYearsNoOverflow() : static
- Add years to the instance with no overflow of months Positive $value travel forward while negative $value travel into the past.
- addYearsWithOverflow() : static
- Add years to the instance.
- addYearWithOverflow() : static
- Add year with overflow.
- 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.
- between() : bool
- Determines if the instance is between two others
- cast() : object
- Cast the current instance into the given class.
- closest() : static
- Get the closest date from the instance.
- compareYearWithMonth() : bool
- Get the month comparison default behavior.
- copy() : static
- Get a copy of the instance.
- create() : static
- 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
- Create a Carbon instance from a specific format.
- 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.
- createFromTimestampMs() : static
- Create a Carbon instance from a timestamp in milliseconds.
- createFromTimestampUTC() : static
- Create a Carbon instance from an UTC timestamp.
- 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
- Create a new safe Carbon instance from a specific date and time.
- day() : static
- Set the instance's day
- diffAsCarbonInterval() : CarbonInterval
- Get the difference as a CarbonInterval 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.
- diffInDays() : int
- Get the difference in days
- diffInDaysFiltered() : int
- Get the difference in days using a filter closure
- diffInHours() : int
- Get the difference in hours.
- diffInHoursFiltered() : int
- Get the difference in hours using a filter closure
- diffInMicroseconds() : int
- Get the difference in microseconds.
- diffInMilliseconds() : int
- Get the difference in milliseconds.
- diffInMinutes() : int
- Get the difference in minutes.
- diffInMonths() : int
- Get the difference in months
- diffInRealHours() : int
- Get the difference in hours using timestamps.
- diffInRealMicroseconds() : int
- Get the difference in microseconds using timestamps.
- diffInRealMilliseconds() : int
- Get the difference in milliseconds using timestamps.
- diffInRealMinutes() : int
- Get the difference in minutes using timestamps.
- diffInRealSeconds() : int
- Get the difference in seconds using timestamps.
- diffInSeconds() : int
- Get the difference in seconds.
- diffInWeekdays() : int
- Get the difference in weekdays
- diffInWeekendDays() : int
- Get the difference in weekend days using a filter
- diffInWeeks() : int
- Get the difference in weeks
- diffInYears() : int
- Get the difference in years
- disableHumanDiffOption() : mixed
- enableHumanDiffOption() : mixed
- endOfCentury() : static
- Resets the date to end of the century and time to 23:59:59
- endOfDay() : static
- Resets the time to 23:59:59 end of day
- endOfDecade() : static
- Resets the date to end of the decade and time to 23:59:59
- endOfHour() : static
- Modify to end of current hour, minutes and seconds become 59
- endOfMillennium() : static
- Resets the date to end of the century and time to 23:59:59
- 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
- endOfQuarter() : static
- Resets the date to end of the quarter and time to 23:59:59
- endOfSecond() : static
- Modify to end of current minute, seconds become 59
- endOfWeek() : static
- Resets the date to end of week (defined in $weekEndsAt) and time to 23:59:59
- endOfYear() : static
- Resets the date to end of the year and time to 23:59:59
- 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.
- 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.
- formatLocalized() : string
- Format the instance with the current locale. You can set the current locale using setlocale() http://php.net/setlocale.
- 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.
- getAvailableLocales() : array<string|int, mixed>
- Returns the list of internally available locales and already loaded custom locales.
- getDays() : array<string|int, mixed>
- Get the days of the week
- getHumanDiffOptions() : int
- getLastErrors() : mixed
- {@inheritdoc}
- getLocale() : string
- Get the current translator locale
- getMidDayAt() : int
- get midday/noon hour
- getTestNow() : static
- Get the Carbon instance (real or mock) to be returned when a "now" instance is created.
- getTranslator() : TranslatorInterface
- Get the translator instance in use
- 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.
- hasMacro() : bool
- Checks if macro is registered.
- 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.
- hour() : static
- Set the instance's hour
- instance() : static
- Create a Carbon instance from a DateTime one.
- 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.
- isCurrentDay() : bool
- Determines if the instance is in the current day.
- isCurrentHour() : bool
- Determines if the instance is in the current hour.
- isCurrentMinute() : bool
- Determines if the instance is in the current minute.
- isCurrentMonth() : bool
- Determines if the instance is in the current month.
- isCurrentQuarter() : bool
- Determines if the instance is in the current month.
- isCurrentSecond() : bool
- Determines if the instance is in the current second.
- isCurrentYear() : bool
- Determines if the instance is in the current year.
- isDayOfWeek() : bool
- Checks if this day is a specific day of the week.
- isEndOfDay() : bool
- Check if the instance is end of day.
- isFriday() : bool
- Checks if this day is a Friday.
- isFuture() : bool
- Determines if the instance is in the future, ie. greater (after) than now.
- isLastMonth() : bool
- Determines if the instance is within the last month.
- isLastOfMonth() : bool
- Check if today is the last day of the Month
- isLastQuarter() : bool
- Determines if the instance is within the last quarter.
- isLastWeek() : bool
- Determines if the instance is within the last week.
- isLastYear() : bool
- Determines if the instance is within the previous year.
- isLeapYear() : bool
- Determines if the instance is a leap year.
- isLongYear() : bool
- Determines if the instance is a long year
- isMicrosecondsFallbackEnabled() : bool
- Return true if microseconds fallback on PHP < 7.1 and 7.1.3 is enabled. false if disabled.
- isMidday() : bool
- Check if the instance is midday.
- isMidnight() : bool
- Check if the instance is start of day / midnight.
- isMonday() : bool
- Checks if this day is a Monday.
- isNextMonth() : bool
- Determines if the instance is within the next month.
- isNextQuarter() : bool
- Determines if the instance is within the next quarter.
- isNextWeek() : bool
- Determines if the instance is within the next week.
- isNextYear() : bool
- Determines if the instance is within next year.
- 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.
- isSameDay() : bool
- Checks if the passed in date is the same exact day as the instance´s day.
- isSameHour() : bool
- Checks if the passed in date is the same exact hour as the instance´s hour.
- isSameMinute() : bool
- Checks if the passed in date is the same exact minute as the instance´s minute.
- 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).
- isSameSecond() : bool
- Checks if the passed in date is the same exact second as the instance´s second.
- isSameYear() : bool
- Checks if the passed in date is in the same year as the instance year.
- isSaturday() : bool
- Checks if this day is a Saturday.
- isStartOfDay() : bool
- Check if the instance is start of day / midnight.
- isSunday() : bool
- Checks if this day is a Sunday.
- isThursday() : bool
- Checks if this day is a Thursday.
- isToday() : bool
- Determines if the instance is today.
- isTomorrow() : bool
- Determines if the instance is tomorrow.
- isTuesday() : bool
- Checks if this day is a Tuesday.
- isWednesday() : bool
- Checks if this day is a Wednesday.
- 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() : array<string|int, mixed>|string
- 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
- 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.
- maxValue() : static
- Create a Carbon instance for the greatest supported date.
- 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.
- minute() : static
- Set the instance's minute
- minValue() : static
- Create a Carbon instance for the lowest supported date.
- mixin() : void
- Mix another object into the class.
- month() : static
- Set the instance's month
- ne() : bool
- Determines if the instance is not equal to another
- next() : static
- Modify to the next occurrence of a given day of the week.
- nextWeekday() : $this
- Go forward to the next weekday.
- nextWeekendDay() : $this
- 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.
- parse() : static
- Create a carbon instance from a string.
- previous() : static
- Modify to the previous occurrence of a given day of the week.
- previousWeekday() : $this
- Go backward to the previous weekday.
- previousWeekendDay() : $this
- Go backward to the previous weekend day.
- resetMacros() : mixed
- Remove all macros.
- resetMonthsOverflow() : void
- Reset the month overflow behavior.
- resetToStringFormat() : void
- Reset the format used to the default when type juggling a Carbon instance to a string
- resetYearsOverflow() : void
- Reset the month overflow behavior.
- second() : static
- Set the instance's second
- secondsSinceMidnight() : int
- The number of seconds since midnight.
- secondsUntilEndOfDay() : int
- The number of seconds until 23:59:59.
- serialize() : string
- Return a serialized string of the instance.
- serializeUsing() : void
- JSON serialize all Carbon instances using the given callback.
- setDate() : static
- Sets the current date of the DateTime object to a different date.
- 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
- setHumanDiffOptions() : mixed
- setLocale() : bool
- Set the current translator locale and indicate if the source locale file exists
- setMidDayAt() : void
- Set midday/noon hour
- setTestNow() : mixed
- 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().
- setTimeFrom() : static
- Set the hour, day, and time for this instance to that of the passed instance.
- setTimeFromTimeString() : static
- Set the time by time string
- setTimezone() : static
- Set the instance's timezone from a string or object
- setToStringFormat() : void
- Set the default format used when type juggling a Carbon instance to a string
- setTranslator() : void
- Set the translator instance to use
- setUtf8() : mixed
- Set if UTF8 will be used for localized date/time
- setWeekendDays() : void
- Set weekend days
- setWeekEndsAt() : void
- Set the last day of week
- setWeekStartsAt() : void
- Set the first day of week
- shouldCompareYearWithMonth() : bool
- Get the month comparison default behavior.
- shouldOverflowMonths() : bool
- Get the month overflow behavior.
- shouldOverflowYears() : bool
- Get the month overflow behavior.
- since() : string
- 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 century and the time to 00:00:00
- 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 minute, seconds 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
- subCenturies() : static
- Remove centuries from the instance
- subCentury() : static
- Remove a century from the instance
- subDay() : static
- Remove a day from the instance
- subDays() : static
- Remove days from the instance
- subHour() : static
- Remove an hour from the instance.
- subHours() : static
- Remove hours from the instance.
- subMinute() : static
- Remove a minute from the instance.
- subMinutes() : static
- Remove minutes from the instance.
- subMonth() : static
- Remove a month from the instance
- subMonthNoOverflow() : static
- Remove a month with no overflow from the instance
- subMonths() : static
- Remove months from the instance
- subMonthsNoOverflow() : static
- Remove months with no overflow from the instance
- subMonthsWithOverflow() : static
- Remove months from the instance
- subMonthWithOverflow() : static
- Remove a month from the instance
- subQuarter() : static
- Remove a quarter from the instance
- subQuarters() : static
- Remove quarters from the instance
- subRealHour() : static
- Remove an hour from the instance.
- subRealHours() : static
- Remove hours from the instance using timestamp.
- subRealMinute() : static
- Remove a minute from the instance using timestamp.
- subRealMinutes() : static
- Remove a minute from the instance using timestamp.
- subRealSecond() : static
- Remove a second from the instance using timestamp.
- subRealSeconds() : static
- Remove seconds from the instance using timestamp.
- subSecond() : static
- Remove a second from the instance
- subSeconds() : static
- Remove seconds from the instance.
- subWeek() : static
- Remove a week from the instance
- subWeekday() : static
- Remove a weekday from the instance
- subWeekdays() : static
- Remove weekdays from the instance
- subWeeks() : static
- Remove weeks to the instance
- subYear() : static
- Remove a year from the instance
- subYearNoOverflow() : static
- Remove year from the instance with no month overflow
- subYears() : static
- Remove years from the instance.
- subYearsNoOverflow() : static
- Remove years from the instance with no month overflow.
- subYearsWithOverflow() : static
- Remove years from the instance.
- subYearWithOverflow() : static
- Remove year from the instance.
- timestamp() : static
- Set the instance's timestamp
- timezone() : static
- Alias for setTimezone()
- 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.
- 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
- toIso8601String() : string
- Format the instance as ISO8601
- toIso8601ZuluString() : string
- Convert the instance to UTC and return as Zulu ISO8601
- toISOString() : null|string
- 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() : null|string
- Return the ISO-8601 string (ex: 1977-04-22T06:00:00Z) with UTC timezone.
- tomorrow() : static
- Create a Carbon instance for tomorrow.
- 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.
- 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
- tz() : static
- Alias for setTimezone()
- until() : string
- useMicrosecondsFallback() : mixed
- Add microseconds to now on PHP < 7.1 and 7.1.3 if set to true, let microseconds to 0 on those PHP versions if false.
- useMonthsOverflow() : void
- Indicates if months should be calculated with overflow.
- useYearsOverflow() : void
- Indicates if years should be calculated with overflow.
- year() : static
- Set the instance's year
- yesterday() : static
- Create a Carbon instance for yesterday.
- expectDateTime() : mixed
- Throws an exception if the given object is not a DateTime and does not implement DateTimeInterface and not in $other.
- fixDiffInterval() : CarbonInterval
- floatDiffInSeconds() : mixed
- resolveCarbon() : static
- Return the Carbon instance passed through, a now instance in the same timezone if null given or parse the input if string given.
- safeCreateDateTimeZone() : DateTimeZone
- Creates a DateTimeZone from a string, DateTimeZone or integer offset.
- translator() : TranslatorInterface
- Initialize the translator instance if necessary.
- createFromFormatAndTimezone() : mixed
- nextOrPreviousDay() : $this
- Go forward or backward to the next week- or weekend-day.
- setLastErrors() : void
- Set last errors.
Constants
DAYS_PER_WEEK
public
mixed
DAYS_PER_WEEK
= 7
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_RELATIVE_TO_NOW
public
mixed
DIFF_RELATIVE_TO_NOW
= 'relative-to-now'
DIFF_RELATIVE_TO_OTHER
public
mixed
DIFF_RELATIVE_TO_OTHER
= 'relative-to-other'
FRIDAY
public
mixed
FRIDAY
= 5
HOURS_PER_DAY
public
mixed
HOURS_PER_DAY
= 24
JUST_NOW
public
mixed
JUST_NOW
= 02
MICROSECONDS_PER_MILLISECOND
public
mixed
MICROSECONDS_PER_MILLISECOND
= 1000
MICROSECONDS_PER_SECOND
public
mixed
MICROSECONDS_PER_SECOND
= 1000000
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
public
mixed
NO_ZERO_DIFF
= 01
ONE_DAY_WORDS
public
mixed
ONE_DAY_WORDS
= 04
RFC7231_FORMAT
RFC7231 DateTime format.
public
string
RFC7231_FORMAT
= 'D, d M Y H:i:s \G\M\T'
SATURDAY
public
mixed
SATURDAY
= 6
SECONDS_PER_MINUTE
public
mixed
SECONDS_PER_MINUTE
= 60
SUNDAY
The day constants.
public
mixed
SUNDAY
= 0
THURSDAY
public
mixed
THURSDAY
= 4
TUESDAY
public
mixed
TUESDAY
= 2
TWO_DAY_WORDS
public
mixed
TWO_DAY_WORDS
= 010
WEDNESDAY
public
mixed
WEDNESDAY
= 3
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
Properties
$age read-only
public
int
$age
does a diffInYears() with default parameters
$day
public
int
$day
$dayOfWeek read-only
public
int
$dayOfWeek
0 (for Sunday) through 6 (for Saturday)
$dayOfWeekIso read-only
public
int
$dayOfWeekIso
1 (for Monday) through 7 (for Sunday)
$dayOfYear read-only
public
int
$dayOfYear
0 through 365
$daysInMonth read-only
public
int
$daysInMonth
number of days in the given month
$dst read-only
public
bool
$dst
daylight savings time indicator, true if DST, false otherwise
$englishDayOfWeek read-only
public
string
$englishDayOfWeek
the day of week in English
$englishMonth read-only
public
string
$englishMonth
the day of week in English
$hour
public
int
$hour
$local read-only
public
bool
$local
checks if the timezone is local, true if local, false otherwise
$localeDayOfWeek read-only
public
string
$localeDayOfWeek
the day of week in current locale LC_TIME
$localeMonth read-only
public
string
$localeMonth
the month in current locale LC_TIME
$micro read-only
public
int
$micro
$minute
public
int
$minute
$month
public
int
$month
$offset read-only
public
int
$offset
the timezone offset in seconds from UTC
$offsetHours read-only
public
int
$offsetHours
the timezone offset in hours from UTC
$PHPIntSize
Customizable PHP_INT_SIZE override.
public
static int
$PHPIntSize
= PHP_INT_SIZE
$quarter read-only
public
int
$quarter
the quarter of this instance, 1 - 4
$second
public
int
$second
$shortEnglishDayOfWeek read-only
public
string
$shortEnglishDayOfWeek
the abbreviated day of week in English
$shortEnglishMonth read-only
public
string
$shortEnglishMonth
the abbreviated day of week in English
$shortLocaleDayOfWeek read-only
public
string
$shortLocaleDayOfWeek
the abbreviated day of week in current locale LC_TIME
$shortLocaleMonth read-only
public
string
$shortLocaleMonth
the abbreviated month in current locale LC_TIME
$timestamp
public
int
$timestamp
seconds since the Unix Epoch
$timezone
public
DateTimeZone
$timezone
the current timezone
$timezoneName read-only
public
string
$timezoneName
$tz
public
DateTimeZone
$tz
alias of timezone
$tzName read-only
public
string
$tzName
$utc read-only
public
bool
$utc
checks if the timezone is UTC, true if UTC, false otherwise
$weekNumberInMonth read-only
public
int
$weekNumberInMonth
1 through 5
$weekOfMonth read-only
public
int
$weekOfMonth
1 through 5
$weekOfYear read-only
public
int
$weekOfYear
ISO-8601 week number of year, weeks starting on Monday
$year
public
int
$year
$yearIso
public
int
$yearIso
$compareYearWithMonth
Indicates if years are compared with month by default so isSameMonth and isSameQuarter have $ofSameYear set to true by default.
protected
static bool
$compareYearWithMonth
= false
$days
Names of days of the week.
protected
static array<string|int, mixed>
$days
= array(self::SUNDAY => 'Sunday', self::MONDAY => 'Monday', self::TUESDAY => 'Tuesday', self::WEDNESDAY => 'Wednesday', self::THURSDAY => 'Thursday', self::FRIDAY => 'Friday', self::SATURDAY => 'Saturday')
$humanDiffOptions
Options for diffForHumans().
protected
static int
$humanDiffOptions
= self::NO_ZERO_DIFF
$lastErrors
The errors that can occur.
protected
static array<string|int, mixed>
$lastErrors
$localMacros
The registered string macros.
protected
static array<string|int, mixed>
$localMacros
= array()
$macros
The registered string macros.
protected
static array<string|int, mixed>
$macros
= []
$microsecondsFallback
Add microseconds to now on PHP < 7.1 and 7.1.3. true by default.
protected
static bool
$microsecondsFallback
= true
$midDayAt
Midday/noon hour.
protected
static int
$midDayAt
= 12
$monthsOverflow
Indicates if months should be calculated with overflow.
protected
static bool
$monthsOverflow
= true
$regexFormats
Format regex patterns.
protected
static array<string|int, mixed>
$regexFormats
= array(
'd' => '(3[01]|[12][0-9]|0[1-9])',
'D' => '([a-zA-Z]{3})',
'j' => '([123][0-9]|[1-9])',
'l' => '([a-zA-Z]{2,})',
'N' => '([1-7])',
'S' => '([a-zA-Z]{2})',
'w' => '([0-6])',
'z' => '(36[0-5]|3[0-5][0-9]|[12][0-9]{2}|[1-9]?[0-9])',
'W' => '(5[012]|[1-4][0-9]|[1-9])',
'F' => '([a-zA-Z]{2,})',
'm' => '(1[012]|0[1-9])',
'M' => '([a-zA-Z]{3})',
'n' => '(1[012]|[1-9])',
't' => '(2[89]|3[01])',
'L' => '(0|1)',
'o' => '([1-9][0-9]{0,4})',
'Y' => '([1-9]?[0-9]{4})',
'y' => '([0-9]{2})',
'a' => '(am|pm)',
'A' => '(AM|PM)',
'B' => '([0-9]{3})',
'g' => '(1[012]|[1-9])',
'G' => '(2[0-3]|1?[0-9])',
'h' => '(1[012]|0[1-9])',
'H' => '(2[0-3]|[01][0-9])',
'i' => '([0-5][0-9])',
's' => '([0-5][0-9])',
'u' => '([0-9]{1,6})',
'v' => '([0-9]{1,3})',
'e' => '([a-zA-Z]{1,5})|([a-zA-Z]*\/[a-zA-Z]*)',
'I' => '(0|1)',
'O' => '([\+\-](1[012]|0[0-9])[0134][05])',
'P' => '([\+\-](1[012]|0[0-9]):[0134][05])',
'T' => '([a-zA-Z]{1,5})',
'Z' => '(-?[1-5]?[0-9]{1,4})',
'U' => '([0-9]*)',
// The formats below are combinations of the above formats.
'c' => '(([1-9]?[0-9]{4})\-(1[012]|0[1-9])\-(3[01]|[12][0-9]|0[1-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])[\+\-](1[012]|0[0-9]):([0134][05]))',
// Y-m-dTH:i:sP
'r' => '(([a-zA-Z]{3}), ([123][0-9]|[1-9]) ([a-zA-Z]{3}) ([1-9]?[0-9]{4}) (2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9]) [\+\-](1[012]|0[0-9])([0134][05]))',
)
$serializer
The custom Carbon JSON serializer.
protected
static callable|null
$serializer
$testNow
A test Carbon instance to be returned when now instances are created.
protected
static Carbon
$testNow
$toStringFormat
Format to use for __toString method when type juggling occurs.
protected
static string
$toStringFormat
= self::DEFAULT_TO_STRING_FORMAT
$translator
A translator to ... er ... translate stuff.
protected
static TranslatorInterface
$translator
$utf8
Will UTF8 encoding be used to print localized date/time ?
protected
static bool
$utf8
= false
$weekendDays
Days of weekend.
protected
static array<string|int, mixed>
$weekendDays
= array(self::SATURDAY, self::SUNDAY)
$weekEndsAt
Last day of week.
protected
static int
$weekEndsAt
= self::SUNDAY
$weekStartsAt
First day of week.
protected
static int
$weekStartsAt
= self::MONDAY
$yearsOverflow
Indicates if years should be calculated with overflow.
protected
static bool
$yearsOverflow
= true
Methods
__call()
Dynamically handle calls to the class.
public
__call(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
- $method : string
- $parameters : array<string|int, mixed>
Tags
Return values
mixed —__callStatic()
Dynamically handle calls to the class.
public
static __callStatic(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
- $method : string
- $parameters : array<string|int, mixed>
Tags
Return values
mixed —__construct()
Create a new Carbon instance.
public
__construct([string|null $time = null ][, DateTimeZone|string|null $tz = 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 : string|null = null
- $tz : DateTimeZone|string|null = null
Return values
mixed —__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
Parameters
- $name : string
Tags
Return values
string|int|bool|DateTimeZone —__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
Return values
void —__set_state()
The __set_state handler.
public
static __set_state(array<string|int, mixed> $array) : static
Parameters
- $array : array<string|int, mixed>
Return values
static —__toString()
Format the instance as a string using the set format
public
__toString() : string
Return values
string —addCenturies()
Add centuries to the instance. Positive $value travels forward while negative $value travels into the past.
public
addCenturies(int $value) : static
Parameters
- $value : int
Return values
static —addCentury()
Add a century to the instance
public
addCentury([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —addDay()
Add a day to the instance
public
addDay([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —addDays()
Add days to the instance. Positive $value travels forward while negative $value travels into the past.
public
addDays(int $value) : static
Parameters
- $value : int
Return values
static —addHour()
Add an hour to the instance.
public
addHour([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —addHours()
Add hours to the instance. Positive $value travels forward while negative $value travels into the past.
public
addHours(int $value) : static
Parameters
- $value : int
Return values
static —addMinute()
Add a minute to the instance.
public
addMinute([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —addMinutes()
Add minutes to the instance using timestamp. Positive $value travels forward while negative $value travels into the past.
public
addMinutes(int $value) : static
Parameters
- $value : int
Return values
static —addMonth()
Add a month to the instance
public
addMonth([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —addMonthNoOverflow()
Add a month with no overflow to the instance
public
addMonthNoOverflow([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —addMonths()
Add months to the instance. Positive $value travels forward while negative $value travels into the past.
public
addMonths(int $value) : static
Parameters
- $value : int
Return values
static —addMonthsNoOverflow()
Add months without overflowing to the instance. Positive $value travels forward while negative $value travels into the past.
public
addMonthsNoOverflow(int $value) : static
Parameters
- $value : int
Return values
static —addMonthsWithOverflow()
Add months to the instance. Positive $value travels forward while negative $value travels into the past.
public
addMonthsWithOverflow(int $value) : static
Parameters
- $value : int
Return values
static —addMonthWithOverflow()
Add a month to the instance
public
addMonthWithOverflow([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —addQuarter()
Add a quarter to the instance
public
addQuarter([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —addQuarters()
Add quarters to the instance. Positive $value travels forward while negative $value travels into the past.
public
addQuarters(int $value) : static
Parameters
- $value : int
Return values
static —addRealHour()
Add an hour to the instance using timestamp.
public
addRealHour([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —addRealHours()
Add hours to the instance using timestamp. Positive $value travels forward while negative $value travels into the past.
public
addRealHours(int $value) : static
Parameters
- $value : int
Return values
static —addRealMinute()
Add a minute to the instance using timestamp.
public
addRealMinute([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —addRealMinutes()
Add minutes to the instance using timestamp. Positive $value travels forward while negative $value travels into the past.
public
addRealMinutes(int $value) : static
Parameters
- $value : int
Return values
static —addRealSecond()
Add a second to the instance using timestamp.
public
addRealSecond([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —addRealSeconds()
Add seconds to the instance using timestamp. Positive $value travels forward while negative $value travels into the past.
public
addRealSeconds(int $value) : static
Parameters
- $value : int
Return values
static —addSecond()
Add a second to the instance.
public
addSecond([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —addSeconds()
Add seconds to the instance. Positive $value travels forward while negative $value travels into the past.
public
addSeconds(int $value) : static
Parameters
- $value : int
Return values
static —addWeek()
Add a week to the instance
public
addWeek([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —addWeekday()
Add a weekday to the instance
public
addWeekday([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —addWeekdays()
Add weekdays to the instance. Positive $value travels forward while negative $value travels into the past.
public
addWeekdays(int $value) : static
Parameters
- $value : int
Return values
static —addWeeks()
Add weeks to the instance. Positive $value travels forward while negative $value travels into the past.
public
addWeeks(int $value) : static
Parameters
- $value : int
Return values
static —addYear()
Add a year to the instance
public
addYear([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —addYearNoOverflow()
Add year with overflow months set to false
public
addYearNoOverflow([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —addYears()
Add years to the instance. Positive $value travel forward while negative $value travel into the past.
public
addYears(int $value) : static
Parameters
- $value : int
Return values
static —addYearsNoOverflow()
Add years to the instance with no overflow of months Positive $value travel forward while negative $value travel into the past.
public
addYearsNoOverflow(int $value) : static
Parameters
- $value : int
Return values
static —addYearsWithOverflow()
Add years to the instance.
public
addYearsWithOverflow(int $value) : static
Positive $value travel forward while negative $value travel into the past.
Parameters
- $value : int
Return values
static —addYearWithOverflow()
Add year with overflow.
public
addYearWithOverflow([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —ago()
Get the difference in a human readable format in the current locale from an other instance given to now
public
ago([bool $absolute = null ][, bool $short = false ][, int $parts = 1 ]) : string
Parameters
- $absolute : bool = null
-
removes time difference modifiers ago, after, etc
- $short : bool = false
-
displays short format of time units
- $parts : int = 1
-
displays number of parts in the interval
Return values
string —average()
Modify the current instance to the average of a given instance (default now) and the current instance.
public
average([Carbon|DateTimeInterface|string|null $date = null ]) : static
Parameters
- $date : Carbon|DateTimeInterface|string|null = null
Return values
static —between()
Determines if the instance is between two others
public
between(Carbon|DateTimeInterface|mixed $date1, Carbon|DateTimeInterface|mixed $date2[, bool $equal = true ]) : bool
Parameters
- $date1 : Carbon|DateTimeInterface|mixed
- $date2 : Carbon|DateTimeInterface|mixed
- $equal : bool = true
-
Indicates if an equal to comparison should be done
Return values
bool —cast()
Cast the current instance into the given class.
public
cast(string $className) : object
Parameters
- $className : string
-
The $className::instance() method will be called to cast the current object.
Return values
object —closest()
Get the closest date from the instance.
public
closest(Carbon|DateTimeInterface|mixed $date1, Carbon|DateTimeInterface|mixed $date2) : static
Parameters
Return values
static —compareYearWithMonth()
Get the month comparison default behavior.
public
static compareYearWithMonth([mixed $compareYearWithMonth = true ]) : bool
Parameters
- $compareYearWithMonth : mixed = true
Return values
bool —copy()
Get a copy of the instance.
public
copy() : static
Return values
static —create()
Create a new Carbon instance from a specific date and time.
public
static create([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|null $tz = null ]) : static
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 : int|null = null
- $month : int|null = null
- $day : int|null = null
- $hour : int|null = null
- $minute : int|null = null
- $second : int|null = null
- $tz : DateTimeZone|string|null = null
Tags
Return values
static —createFromDate()
Create a Carbon instance from just a date. The time portion is set to now.
public
static createFromDate([int|null $year = null ][, int|null $month = null ][, int|null $day = null ][, DateTimeZone|string|null $tz = null ]) : static
Parameters
- $year : int|null = null
- $month : int|null = null
- $day : int|null = null
- $tz : DateTimeZone|string|null = null
Tags
Return values
static —createFromFormat()
Create a Carbon instance from a specific format.
public
static createFromFormat(string $format, string $time[, DateTimeZone|string|null $tz = null ]) : static
Parameters
- $format : string
-
Datetime format
- $time : string
- $tz : DateTimeZone|string|null = null
Tags
Return values
static —createFromTime()
Create a Carbon instance from just a time. The date portion is set to today.
public
static createFromTime([int|null $hour = null ][, int|null $minute = null ][, int|null $second = null ][, DateTimeZone|string|null $tz = null ]) : static
Parameters
- $hour : int|null = null
- $minute : int|null = null
- $second : int|null = null
- $tz : DateTimeZone|string|null = null
Tags
Return values
static —createFromTimestamp()
Create a Carbon instance from a timestamp.
public
static createFromTimestamp(int $timestamp[, DateTimeZone|string|null $tz = null ]) : static
Parameters
- $timestamp : int
- $tz : DateTimeZone|string|null = null
Return values
static —createFromTimestampMs()
Create a Carbon instance from a timestamp in milliseconds.
public
static createFromTimestampMs(int $timestamp[, DateTimeZone|string|null $tz = null ]) : static
Parameters
- $timestamp : int
- $tz : DateTimeZone|string|null = null
Return values
static —createFromTimestampUTC()
Create a Carbon instance from an UTC timestamp.
public
static createFromTimestampUTC(int $timestamp) : static
Parameters
- $timestamp : int
Return values
static —createFromTimeString()
Create a Carbon instance from a time string. The date portion is set to today.
public
static createFromTimeString(string $time[, DateTimeZone|string|null $tz = null ]) : static
Parameters
- $time : string
- $tz : DateTimeZone|string|null = null
Tags
Return values
static —createMidnightDate()
Create a Carbon instance from just a date. The time portion is set to midnight.
public
static createMidnightDate([int|null $year = null ][, int|null $month = null ][, int|null $day = null ][, DateTimeZone|string|null $tz = null ]) : static
Parameters
- $year : int|null = null
- $month : int|null = null
- $day : int|null = null
- $tz : DateTimeZone|string|null = null
Return values
static —createSafe()
Create a new safe Carbon instance from a specific date and time.
public
static createSafe([int|null $year = null ][, int|null $month = null ][, int|null $day = null ][, int|null $hour = null ][, int|null $minute = null ][, int|null $second = null ][, DateTimeZone|string|null $tz = null ]) : static
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 \InvalidArgumentException 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
- $tz : DateTimeZone|string|null = null
Tags
Return values
static —day()
Set the instance's day
public
day(int $value) : static
Parameters
- $value : int
Return values
static —diffAsCarbonInterval()
Get the difference as a CarbonInterval instance.
public
diffAsCarbonInterval([Carbon|DateTimeInterface|string|null $date = null ][, bool $absolute = true ][, bool $trimMicroseconds = true ]) : CarbonInterval
Pass false as second argument to get a microseconds-precise interval. Else microseconds in the original interval will not be kept.
Parameters
- $date : Carbon|DateTimeInterface|string|null = null
- $absolute : bool = true
-
Get the absolute of the difference
- $trimMicroseconds : bool = true
-
(true by default)
Return values
CarbonInterval —diffFiltered()
Get the difference by the given interval using a filter closure
public
diffFiltered(CarbonInterval $ci, Closure $callback[, Carbon|DateTimeInterface|string|null $date = null ][, bool $absolute = true ]) : int
Parameters
- $ci : CarbonInterval
-
An interval to traverse by
- $callback : Closure
- $date : Carbon|DateTimeInterface|string|null = null
- $absolute : bool = true
-
Get the absolute of the difference
Return values
int —diffForHumans()
Get the difference in a human readable format in the current locale.
public
diffForHumans([Carbon|null $other = null ][, bool $absolute = false ][, bool $short = false ][, int $parts = 1 ]) : string
When comparing a value in the past to default now: 1 hour ago 5 months ago
When comparing a value in the future to default now: 1 hour from now 5 months from now
When comparing a value in the past to another value: 1 hour before 5 months before
When comparing a value in the future to another value: 1 hour after 5 months after
Parameters
- $other : Carbon|null = null
- $absolute : bool = false
-
removes time difference modifiers ago, after, etc
- $short : bool = false
-
displays short format of time units
- $parts : int = 1
-
displays number of parts in the interval
Return values
string —diffInDays()
Get the difference in days
public
diffInDays([Carbon|DateTimeInterface|string|null $date = null ][, bool $absolute = true ]) : int
Parameters
- $date : Carbon|DateTimeInterface|string|null = null
- $absolute : bool = true
-
Get the absolute of the difference
Return values
int —diffInDaysFiltered()
Get the difference in days using a filter closure
public
diffInDaysFiltered(Closure $callback[, Carbon|DateTimeInterface|string|null $date = null ][, bool $absolute = true ]) : int
Parameters
- $callback : Closure
- $date : Carbon|DateTimeInterface|string|null = null
- $absolute : bool = true
-
Get the absolute of the difference
Return values
int —diffInHours()
Get the difference in hours.
public
diffInHours([Carbon|DateTimeInterface|string|null $date = null ][, bool $absolute = true ]) : int
Parameters
- $date : Carbon|DateTimeInterface|string|null = null
- $absolute : bool = true
-
Get the absolute of the difference
Return values
int —diffInHoursFiltered()
Get the difference in hours using a filter closure
public
diffInHoursFiltered(Closure $callback[, Carbon|DateTimeInterface|string|null $date = null ][, bool $absolute = true ]) : int
Parameters
- $callback : Closure
- $date : Carbon|DateTimeInterface|string|null = null
- $absolute : bool = true
-
Get the absolute of the difference
Return values
int —diffInMicroseconds()
Get the difference in microseconds.
public
diffInMicroseconds([Carbon|DateTimeInterface|string|null $date = null ][, bool $absolute = true ]) : int
Parameters
- $date : Carbon|DateTimeInterface|string|null = null
- $absolute : bool = true
-
Get the absolute of the difference
Return values
int —diffInMilliseconds()
Get the difference in milliseconds.
public
diffInMilliseconds([Carbon|DateTimeInterface|string|null $date = null ][, bool $absolute = true ]) : int
Parameters
- $date : Carbon|DateTimeInterface|string|null = null
- $absolute : bool = true
-
Get the absolute of the difference
Return values
int —diffInMinutes()
Get the difference in minutes.
public
diffInMinutes([Carbon|DateTimeInterface|string|null $date = null ][, bool $absolute = true ]) : int
Parameters
- $date : Carbon|DateTimeInterface|string|null = null
- $absolute : bool = true
-
Get the absolute of the difference
Return values
int —diffInMonths()
Get the difference in months
public
diffInMonths([Carbon|DateTimeInterface|string|null $date = null ][, bool $absolute = true ]) : int
Parameters
- $date : Carbon|DateTimeInterface|string|null = null
- $absolute : bool = true
-
Get the absolute of the difference
Return values
int —diffInRealHours()
Get the difference in hours using timestamps.
public
diffInRealHours([Carbon|DateTimeInterface|string|null $date = null ][, bool $absolute = true ]) : int
Parameters
- $date : Carbon|DateTimeInterface|string|null = null
- $absolute : bool = true
-
Get the absolute of the difference
Return values
int —diffInRealMicroseconds()
Get the difference in microseconds using timestamps.
public
diffInRealMicroseconds([Carbon|DateTimeInterface|string|null $date = null ][, bool $absolute = true ]) : int
Parameters
- $date : Carbon|DateTimeInterface|string|null = null
- $absolute : bool = true
-
Get the absolute of the difference
Return values
int —diffInRealMilliseconds()
Get the difference in milliseconds using timestamps.
public
diffInRealMilliseconds([Carbon|DateTimeInterface|string|null $date = null ][, bool $absolute = true ]) : int
Parameters
- $date : Carbon|DateTimeInterface|string|null = null
- $absolute : bool = true
-
Get the absolute of the difference
Return values
int —diffInRealMinutes()
Get the difference in minutes using timestamps.
public
diffInRealMinutes([Carbon|DateTimeInterface|string|null $date = null ][, bool $absolute = true ]) : int
Parameters
- $date : Carbon|DateTimeInterface|string|null = null
- $absolute : bool = true
-
Get the absolute of the difference
Return values
int —diffInRealSeconds()
Get the difference in seconds using timestamps.
public
diffInRealSeconds([Carbon|DateTimeInterface|string|null $date = null ][, bool $absolute = true ]) : int
Parameters
- $date : Carbon|DateTimeInterface|string|null = null
- $absolute : bool = true
-
Get the absolute of the difference
Return values
int —diffInSeconds()
Get the difference in seconds.
public
diffInSeconds([Carbon|DateTimeInterface|string|null $date = null ][, bool $absolute = true ]) : int
Parameters
- $date : Carbon|DateTimeInterface|string|null = null
- $absolute : bool = true
-
Get the absolute of the difference
Return values
int —diffInWeekdays()
Get the difference in weekdays
public
diffInWeekdays([Carbon|DateTimeInterface|string|null $date = null ][, bool $absolute = true ]) : int
Parameters
- $date : Carbon|DateTimeInterface|string|null = null
- $absolute : bool = true
-
Get the absolute of the difference
Return values
int —diffInWeekendDays()
Get the difference in weekend days using a filter
public
diffInWeekendDays([Carbon|DateTimeInterface|string|null $date = null ][, bool $absolute = true ]) : int
Parameters
- $date : Carbon|DateTimeInterface|string|null = null
- $absolute : bool = true
-
Get the absolute of the difference
Return values
int —diffInWeeks()
Get the difference in weeks
public
diffInWeeks([Carbon|DateTimeInterface|string|null $date = null ][, bool $absolute = true ]) : int
Parameters
- $date : Carbon|DateTimeInterface|string|null = null
- $absolute : bool = true
-
Get the absolute of the difference
Return values
int —diffInYears()
Get the difference in years
public
diffInYears([Carbon|DateTimeInterface|string|null $date = null ][, bool $absolute = true ]) : int
Parameters
- $date : Carbon|DateTimeInterface|string|null = null
- $absolute : bool = true
-
Get the absolute of the difference
Return values
int —disableHumanDiffOption()
public
static disableHumanDiffOption(int $humanDiffOption) : mixed
Parameters
- $humanDiffOption : int
Return values
mixed —enableHumanDiffOption()
public
static enableHumanDiffOption(int $humanDiffOption) : mixed
Parameters
- $humanDiffOption : int
Return values
mixed —endOfCentury()
Resets the date to end of the century and time to 23:59:59
public
endOfCentury() : static
Return values
static —endOfDay()
Resets the time to 23:59:59 end of day
public
endOfDay() : static
Return values
static —endOfDecade()
Resets the date to end of the decade and time to 23:59:59
public
endOfDecade() : static
Return values
static —endOfHour()
Modify to end of current hour, minutes and seconds become 59
public
endOfHour() : static
Return values
static —endOfMillennium()
Resets the date to end of the century and time to 23:59:59
public
endOfMillennium() : static
Return values
static —endOfMinute()
Modify to end of current minute, seconds become 59
public
endOfMinute() : static
Return values
static —endOfMonth()
Resets the date to end of the month and time to 23:59:59
public
endOfMonth() : static
Return values
static —endOfQuarter()
Resets the date to end of the quarter and time to 23:59:59
public
endOfQuarter() : static
Return values
static —endOfSecond()
Modify to end of current minute, seconds become 59
public
endOfSecond() : static
Return values
static —endOfWeek()
Resets the date to end of week (defined in $weekEndsAt) and time to 23:59:59
public
endOfWeek() : static
Return values
static —endOfYear()
Resets the date to end of the year and time to 23:59:59
public
endOfYear() : static
Return values
static —eq()
Determines if the instance is equal to another
public
eq(Carbon|DateTimeInterface|mixed $date) : bool
Parameters
- $date : Carbon|DateTimeInterface|mixed
Return values
bool —equalTo()
Determines if the instance is equal to another
public
equalTo(Carbon|DateTimeInterface|mixed $date) : bool
Parameters
- $date : Carbon|DateTimeInterface|mixed
Tags
Return values
bool —executeWithLocale()
Set the current locale to the given, execute the passed function, reset the locale to previous one, then return the result of the closure (or null if the closure was void).
public
static executeWithLocale(string $locale, mixed $func) : mixed
Parameters
- $locale : string
-
locale ex. en
- $func : mixed
Return values
mixed —farthest()
Get the farthest date from the instance.
public
farthest(Carbon|DateTimeInterface|mixed $date1, Carbon|DateTimeInterface|mixed $date2) : static
Parameters
Return values
static —firstOfMonth()
Modify to the first occurrence of a given day of the week in the current month. If no dayOfWeek is provided, modify to the first day of the current month. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
public
firstOfMonth([int|null $dayOfWeek = null ]) : static
Parameters
- $dayOfWeek : int|null = null
Return values
static —firstOfQuarter()
Modify to the first occurrence of a given day of the week in the current quarter. If no dayOfWeek is provided, modify to the first day of the current quarter. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
public
firstOfQuarter([int|null $dayOfWeek = null ]) : static
Parameters
- $dayOfWeek : int|null = null
-
day of the week default null
Return values
static —firstOfYear()
Modify to the first occurrence of a given day of the week in the current year. If no dayOfWeek is provided, modify to the first day of the current year. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
public
firstOfYear([int|null $dayOfWeek = null ]) : static
Parameters
- $dayOfWeek : int|null = null
-
day of the week default null
Return values
static —formatLocalized()
Format the instance with the current locale. You can set the current locale using setlocale() http://php.net/setlocale.
public
formatLocalized(string $format) : string
Parameters
- $format : string
Return values
string —from()
public
from([Carbon|null $other = null ][, bool $absolute = false ][, bool $short = false ][, int $parts = 1 ]) : string
Parameters
- $other : Carbon|null = null
- $absolute : bool = false
-
removes time difference modifiers ago, after, etc
- $short : bool = false
-
displays short format of time units
- $parts : int = 1
-
displays number of parts in the interval
Tags
Return values
string —fromNow()
Get the difference in a human readable format in the current locale from current instance to now.
public
fromNow([bool $absolute = null ][, bool $short = false ][, int $parts = 1 ]) : string
Parameters
- $absolute : bool = null
-
removes time difference modifiers ago, after, etc
- $short : bool = false
-
displays short format of time units
- $parts : int = 1
-
displays number of parts in the interval
Return values
string —fromSerialized()
Create an instance from a serialized string.
public
static fromSerialized(string $value) : static
Parameters
- $value : string
Tags
Return values
static —getAvailableLocales()
Returns the list of internally available locales and already loaded custom locales.
public
static getAvailableLocales() : array<string|int, mixed>
(It will ignore custom translator dynamic loading.)
Return values
array<string|int, mixed> —getDays()
Get the days of the week
public
static getDays() : array<string|int, mixed>
Return values
array<string|int, mixed> —getHumanDiffOptions()
public
static getHumanDiffOptions() : int
Return values
int —getLastErrors()
{@inheritdoc}
public
static getLastErrors() : mixed
Return values
mixed —getLocale()
Get the current translator locale
public
static getLocale() : string
Return values
string —getMidDayAt()
get midday/noon hour
public
static getMidDayAt() : int
Return values
int —getTestNow()
Get the Carbon instance (real or mock) to be returned when a "now" instance is created.
public
static getTestNow() : static
Return values
static —the current instance used for testing
getTranslator()
Get the translator instance in use
public
static getTranslator() : TranslatorInterface
Return values
TranslatorInterface —getWeekendDays()
Get weekend days
public
static getWeekendDays() : array<string|int, mixed>
Return values
array<string|int, mixed> —getWeekEndsAt()
Get the last day of week
public
static getWeekEndsAt() : int
Return values
int —getWeekStartsAt()
Get the first day of week
public
static getWeekStartsAt() : int
Return values
int —greaterThan()
Determines if the instance is greater (after) than another
public
greaterThan(Carbon|DateTimeInterface|mixed $date) : bool
Parameters
- $date : Carbon|DateTimeInterface|mixed
Tags
Return values
bool —greaterThanOrEqualTo()
Determines if the instance is greater (after) than or equal to another
public
greaterThanOrEqualTo(Carbon|DateTimeInterface|mixed $date) : bool
Parameters
- $date : Carbon|DateTimeInterface|mixed
Tags
Return values
bool —gt()
Determines if the instance is greater (after) than another
public
gt(Carbon|DateTimeInterface|mixed $date) : bool
Parameters
- $date : Carbon|DateTimeInterface|mixed
Return values
bool —gte()
Determines if the instance is greater (after) than or equal to another
public
gte(Carbon|DateTimeInterface|mixed $date) : bool
Parameters
- $date : Carbon|DateTimeInterface|mixed
Return values
bool —hasFormat()
Checks if the (date)time string is in a given format.
public
static hasFormat(string $date, string $format) : bool
Parameters
- $date : string
- $format : string
Return values
bool —hasMacro()
Checks if macro is registered.
public
static hasMacro(string $name) : bool
Parameters
- $name : string
Return values
bool —hasRelativeKeywords()
Determine if a time string will produce a relative date.
public
static hasRelativeKeywords(string $time) : bool
Parameters
- $time : string
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
hour()
Set the instance's hour
public
hour(int $value) : static
Parameters
- $value : int
Return values
static —instance()
Create a Carbon instance from a DateTime one.
public
static instance(DateTime|DateTimeInterface $date) : static
Parameters
- $date : DateTime|DateTimeInterface
Return values
static —isAfter()
Determines if the instance is greater (after) than another
public
isAfter(Carbon|DateTimeInterface|mixed $date) : bool
Parameters
- $date : Carbon|DateTimeInterface|mixed
Tags
Return values
bool —isBefore()
Determines if the instance is less (before) than another
public
isBefore(Carbon|DateTimeInterface|mixed $date) : bool
Parameters
- $date : Carbon|DateTimeInterface|mixed
Tags
Return values
bool —isBetween()
Determines if the instance is between two others
public
isBetween(Carbon|DateTimeInterface|mixed $date1, Carbon|DateTimeInterface|mixed $date2[, bool $equal = true ]) : bool
Parameters
- $date1 : Carbon|DateTimeInterface|mixed
- $date2 : Carbon|DateTimeInterface|mixed
- $equal : bool = true
-
Indicates if a > and < comparison should be used or <= or >=
Return values
bool —isBirthday()
Check if its the birthday. Compares the date/month values of the two dates.
public
isBirthday([Carbon|DateTimeInterface|null $date = null ]) : bool
Parameters
- $date : Carbon|DateTimeInterface|null = null
-
The instance to compare with or null to use current day.
Return values
bool —isCurrentDay()
Determines if the instance is in the current day.
public
isCurrentDay() : bool
Return values
bool —isCurrentHour()
Determines if the instance is in the current hour.
public
isCurrentHour() : bool
Return values
bool —isCurrentMinute()
Determines if the instance is in the current minute.
public
isCurrentMinute() : bool
Return values
bool —isCurrentMonth()
Determines if the instance is in the current month.
public
isCurrentMonth([bool $ofSameYear = null ]) : bool
Parameters
- $ofSameYear : bool = null
-
Check if it is the same month in the same year.
Return values
bool —isCurrentQuarter()
Determines if the instance is in the current month.
public
isCurrentQuarter() : bool
Return values
bool —isCurrentSecond()
Determines if the instance is in the current second.
public
isCurrentSecond() : bool
Return values
bool —isCurrentYear()
Determines if the instance is in the current year.
public
isCurrentYear() : bool
Return values
bool —isDayOfWeek()
Checks if this day is a specific day of the week.
public
isDayOfWeek(int $dayOfWeek) : bool
Parameters
- $dayOfWeek : int
Return values
bool —isEndOfDay()
Check if the instance is end of day.
public
isEndOfDay([bool $checkMicroseconds = false ]) : bool
Parameters
- $checkMicroseconds : bool = false
-
check time at microseconds precision /!\ Warning, this is not reliable with PHP < 7.1.4
Return values
bool —isFriday()
Checks if this day is a Friday.
public
isFriday() : bool
Return values
bool —isFuture()
Determines if the instance is in the future, ie. greater (after) than now.
public
isFuture() : bool
Return values
bool —isLastMonth()
Determines if the instance is within the last month.
public
isLastMonth() : bool
Return values
bool —isLastOfMonth()
Check if today is the last day of the Month
public
isLastOfMonth() : bool
Return values
bool —isLastQuarter()
Determines if the instance is within the last quarter.
public
isLastQuarter() : bool
Return values
bool —isLastWeek()
Determines if the instance is within the last week.
public
isLastWeek() : bool
Return values
bool —isLastYear()
Determines if the instance is within the previous year.
public
isLastYear() : bool
Return values
bool —isLeapYear()
Determines if the instance is a leap year.
public
isLeapYear() : bool
Return values
bool —isLongYear()
Determines if the instance is a long year
public
isLongYear() : bool
Tags
Return values
bool —isMicrosecondsFallbackEnabled()
Return true if microseconds fallback on PHP < 7.1 and 7.1.3 is enabled. false if disabled.
public
static isMicrosecondsFallbackEnabled() : bool
Return values
bool —isMidday()
Check if the instance is midday.
public
isMidday() : bool
Return values
bool —isMidnight()
Check if the instance is start of day / midnight.
public
isMidnight() : bool
Return values
bool —isMonday()
Checks if this day is a Monday.
public
isMonday() : bool
Return values
bool —isNextMonth()
Determines if the instance is within the next month.
public
isNextMonth() : bool
Return values
bool —isNextQuarter()
Determines if the instance is within the next quarter.
public
isNextQuarter() : bool
Return values
bool —isNextWeek()
Determines if the instance is within the next week.
public
isNextWeek() : bool
Return values
bool —isNextYear()
Determines if the instance is within next year.
public
isNextYear() : bool
Return values
bool —isPast()
Determines if the instance is in the past, ie. less (before) than now.
public
isPast() : bool
Return values
bool —isSameAs()
Compares the formatted values of the two dates.
public
isSameAs(string $format[, Carbon|DateTimeInterface|null $date = null ]) : bool
Parameters
- $format : string
-
The date formats to compare.
- $date : Carbon|DateTimeInterface|null = null
-
The instance to compare with or null to use current day.
Tags
Return values
bool —isSameDay()
Checks if the passed in date is the same exact day as the instance´s day.
public
isSameDay([Carbon|DateTimeInterface|null $date = null ]) : bool
Parameters
- $date : Carbon|DateTimeInterface|null = null
-
The instance to compare with or null to use the current date.
Return values
bool —isSameHour()
Checks if the passed in date is the same exact hour as the instance´s hour.
public
isSameHour([Carbon|DateTimeInterface|null $date = null ]) : bool
Parameters
- $date : Carbon|DateTimeInterface|null = null
-
The instance to compare with or null to use the current date.
Return values
bool —isSameMinute()
Checks if the passed in date is the same exact minute as the instance´s minute.
public
isSameMinute([Carbon|DateTimeInterface|null $date = null ]) : bool
Parameters
- $date : Carbon|DateTimeInterface|null = null
-
The instance to compare with or null to use the current date.
Return values
bool —isSameMonth()
Checks if the passed in date is in the same month as the instance´s month.
public
isSameMonth([Carbon|DateTimeInterface|null $date = null ][, bool $ofSameYear = null ]) : bool
Note that this defaults to only comparing the month while ignoring the year. To test if it is the same exact month of the same year, pass in true as the second parameter.
Parameters
- $date : Carbon|DateTimeInterface|null = null
-
The instance to compare with or null to use the current date.
- $ofSameYear : bool = null
-
Check if it is the same month in the same year.
Return values
bool —isSameQuarter()
Checks if the passed in date is in the same quarter as the instance quarter (and year if needed).
public
isSameQuarter([Carbon|DateTimeInterface|null $date = null ][, bool $ofSameYear = null ]) : bool
Parameters
- $date : Carbon|DateTimeInterface|null = null
-
The instance to compare with or null to use current day.
- $ofSameYear : bool = null
-
Check if it is the same month in the same year.
Return values
bool —isSameSecond()
Checks if the passed in date is the same exact second as the instance´s second.
public
isSameSecond([Carbon|DateTimeInterface|null $date = null ]) : bool
Parameters
- $date : Carbon|DateTimeInterface|null = null
-
The instance to compare with or null to use the current date.
Return values
bool —isSameYear()
Checks if the passed in date is in the same year as the instance year.
public
isSameYear([Carbon|DateTimeInterface|null $date = null ]) : bool
Parameters
- $date : Carbon|DateTimeInterface|null = null
-
The instance to compare with or null to use current day.
Return values
bool —isSaturday()
Checks if this day is a Saturday.
public
isSaturday() : bool
Return values
bool —isStartOfDay()
Check if the instance is start of day / midnight.
public
isStartOfDay([bool $checkMicroseconds = false ]) : bool
Parameters
- $checkMicroseconds : bool = false
-
check time at microseconds precision /!\ Warning, this is not reliable with PHP < 7.1.4
Return values
bool —isSunday()
Checks if this day is a Sunday.
public
isSunday() : bool
Return values
bool —isThursday()
Checks if this day is a Thursday.
public
isThursday() : bool
Return values
bool —isToday()
Determines if the instance is today.
public
isToday() : bool
Return values
bool —isTomorrow()
Determines if the instance is tomorrow.
public
isTomorrow() : bool
Return values
bool —isTuesday()
Checks if this day is a Tuesday.
public
isTuesday() : bool
Return values
bool —isWednesday()
Checks if this day is a Wednesday.
public
isWednesday() : bool
Return values
bool —isWeekday()
Determines if the instance is a weekday.
public
isWeekday() : bool
Return values
bool —isWeekend()
Determines if the instance is a weekend day.
public
isWeekend() : bool
Return values
bool —isYesterday()
Determines if the instance is yesterday.
public
isYesterday() : bool
Return values
bool —jsonSerialize()
Prepare the object for JSON serialization.
public
jsonSerialize() : array<string|int, mixed>|string
Return values
array<string|int, mixed>|string —lastOfMonth()
Modify to the last occurrence of a given day of the week in the current month. If no dayOfWeek is provided, modify to the last day of the current month. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
public
lastOfMonth([int|null $dayOfWeek = null ]) : static
Parameters
- $dayOfWeek : int|null = null
Return values
static —lastOfQuarter()
Modify to the last occurrence of a given day of the week in the current quarter. If no dayOfWeek is provided, modify to the last day of the current quarter. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
public
lastOfQuarter([int|null $dayOfWeek = null ]) : static
Parameters
- $dayOfWeek : int|null = null
-
day of the week default null
Return values
static —lastOfYear()
Modify to the last occurrence of a given day of the week in the current year. If no dayOfWeek is provided, modify to the last day of the current year. Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
public
lastOfYear([int|null $dayOfWeek = null ]) : static
Parameters
- $dayOfWeek : int|null = null
-
day of the week default null
Return values
static —lessThan()
Determines if the instance is less (before) than another
public
lessThan(Carbon|DateTimeInterface|mixed $date) : bool
Parameters
- $date : Carbon|DateTimeInterface|mixed
Tags
Return values
bool —lessThanOrEqualTo()
Determines if the instance is less (before) or equal to another
public
lessThanOrEqualTo(Carbon|DateTimeInterface|mixed $date) : bool
Parameters
- $date : Carbon|DateTimeInterface|mixed
Tags
Return values
bool —localeHasDiffOneDayWords()
Returns true if the given locale is internally supported and has words for 1-day diff (just now, yesterday, tomorrow).
public
static localeHasDiffOneDayWords(string $locale) : bool
Support is considered enabled if the 3 words are translated in the given locale.
Parameters
- $locale : string
-
locale ex. en
Return values
bool —localeHasDiffSyntax()
Returns true if the given locale is internally supported and has diff syntax support (ago, from now, before, after).
public
static localeHasDiffSyntax(string $locale) : bool
Support is considered enabled if the 4 sentences are translated in the given locale.
Parameters
- $locale : string
-
locale ex. en
Return values
bool —localeHasDiffTwoDayWords()
Returns true if the given locale is internally supported and has words for 2-days diff (before yesterday, after tomorrow).
public
static localeHasDiffTwoDayWords(string $locale) : bool
Support is considered enabled if the 2 words are translated in the given locale.
Parameters
- $locale : string
-
locale ex. en
Return values
bool —localeHasPeriodSyntax()
Returns true if the given locale is internally supported and has period syntax support (X times, every X, from X, to X).
public
static localeHasPeriodSyntax(string $locale) : bool
Support is considered enabled if the 4 sentences are translated in the given locale.
Parameters
- $locale : string
-
locale ex. en
Return values
bool —localeHasShortUnits()
Returns true if the given locale is internally supported and has short-units support.
public
static localeHasShortUnits(string $locale) : bool
Support is considered enabled if either year, day or hour has a short variant translated.
Parameters
- $locale : string
-
locale ex. en
Return values
bool —lt()
Determines if the instance is less (before) than another
public
lt(Carbon|DateTimeInterface|mixed $date) : bool
Parameters
- $date : Carbon|DateTimeInterface|mixed
Return values
bool —lte()
Determines if the instance is less (before) or equal to another
public
lte(Carbon|DateTimeInterface|mixed $date) : bool
Parameters
- $date : Carbon|DateTimeInterface|mixed
Return values
bool —macro()
Register a custom macro.
public
static macro(string $name, object|callable $macro) : void
Parameters
- $name : string
- $macro : object|callable
Return values
void —make()
Make a Carbon instance from given variable if possible.
public
static make(mixed $var) : 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
Return values
static|null —max()
Get the maximum instance between a given instance (default now) and the current instance.
public
max([Carbon|DateTimeInterface|string|null $date = null ]) : static
Parameters
- $date : Carbon|DateTimeInterface|string|null = null
Return values
static —maximum()
Get the maximum instance between a given instance (default now) and the current instance.
public
maximum([Carbon|DateTimeInterface|mixed $date = null ]) : static
Parameters
- $date : Carbon|DateTimeInterface|mixed = null
Tags
Return values
static —maxValue()
Create a Carbon instance for the greatest supported date.
public
static maxValue() : static
Return values
static —midDay()
Modify to midday, default to self::$midDayAt
public
midDay() : static
Return values
static —min()
Get the minimum instance between a given instance (default now) and the current instance.
public
min([Carbon|DateTimeInterface|string|null $date = null ]) : static
Parameters
- $date : Carbon|DateTimeInterface|string|null = null
Return values
static —minimum()
Get the minimum instance between a given instance (default now) and the current instance.
public
minimum([Carbon|DateTimeInterface|mixed $date = null ]) : static
Parameters
- $date : Carbon|DateTimeInterface|mixed = null
Tags
Return values
static —minute()
Set the instance's minute
public
minute(int $value) : static
Parameters
- $value : int
Return values
static —minValue()
Create a Carbon instance for the lowest supported date.
public
static minValue() : static
Return values
static —mixin()
Mix another object into the class.
public
static mixin(object $mixin) : void
Parameters
- $mixin : object
Return values
void —month()
Set the instance's month
public
month(int $value) : static
Parameters
- $value : int
Return values
static —ne()
Determines if the instance is not equal to another
public
ne(Carbon|DateTimeInterface|mixed $date) : bool
Parameters
- $date : Carbon|DateTimeInterface|mixed
Return values
bool —next()
Modify to the next occurrence of a given day of the week.
public
next([int|null $dayOfWeek = null ]) : static
If no dayOfWeek 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.
Parameters
- $dayOfWeek : int|null = null
Return values
static —nextWeekday()
Go forward to the next weekday.
public
nextWeekday() : $this
Return values
$this —nextWeekendDay()
Go forward to the next weekend day.
public
nextWeekendDay() : $this
Return values
$this —notEqualTo()
Determines if the instance is not equal to another
public
notEqualTo(Carbon|DateTimeInterface|mixed $date) : bool
Parameters
- $date : Carbon|DateTimeInterface|mixed
Tags
Return values
bool —now()
Get a Carbon instance for the current date and time.
public
static now([DateTimeZone|string|null $tz = null ]) : static
Parameters
- $tz : DateTimeZone|string|null = null
Return values
static —nowWithSameTz()
Returns a present instance in the same timezone.
public
nowWithSameTz() : static
Return values
static —nthOfMonth()
Modify to the given occurrence of a given day of the week in the current month. If the calculated occurrence is outside the scope of the current month, then return false and no modifications are made.
public
nthOfMonth(int $nth, int $dayOfWeek) : mixed
Use the supplied constants to indicate the desired dayOfWeek, ex. static::MONDAY.
Parameters
- $nth : int
- $dayOfWeek : int
Return values
mixed —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
Return values
mixed —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
Return values
mixed —parse()
Create a carbon instance from a string.
public
static parse([string|null $time = null ][, DateTimeZone|string|null $tz = 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 : string|null = null
- $tz : DateTimeZone|string|null = null
Return values
static —previous()
Modify to the previous occurrence of a given day of the week.
public
previous([int|null $dayOfWeek = null ]) : static
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.
Parameters
- $dayOfWeek : int|null = null
Return values
static —previousWeekday()
Go backward to the previous weekday.
public
previousWeekday() : $this
Return values
$this —previousWeekendDay()
Go backward to the previous weekend day.
public
previousWeekendDay() : $this
Return values
$this —resetMacros()
Remove all macros.
public
static resetMacros() : mixed
Return values
mixed —resetMonthsOverflow()
Reset the month overflow behavior.
public
static resetMonthsOverflow() : void
Return values
void —resetToStringFormat()
Reset the format used to the default when type juggling a Carbon instance to a string
public
static resetToStringFormat() : void
Return values
void —resetYearsOverflow()
Reset the month overflow behavior.
public
static resetYearsOverflow() : void
Return values
void —second()
Set the instance's second
public
second(int $value) : static
Parameters
- $value : int
Return values
static —secondsSinceMidnight()
The number of seconds since midnight.
public
secondsSinceMidnight() : int
Return values
int —secondsUntilEndOfDay()
The number of seconds until 23:59:59.
public
secondsUntilEndOfDay() : int
Return values
int —serialize()
Return a serialized string of the instance.
public
serialize() : string
Return values
string —serializeUsing()
JSON serialize all Carbon instances using the given callback.
public
static serializeUsing(callable $callback) : void
Parameters
- $callback : callable
Return values
void —setDate()
Sets the current date of the DateTime object to a different date.
public
setDate(int $year, int $month, int $day) : static
Calls modify as a workaround for a php bug
Parameters
- $year : int
- $month : int
- $day : int
Tags
Return values
static —setDateFrom()
Set the year, month, and date for this instance to that of the passed instance.
public
setDateFrom(Carbon|DateTimeInterface $date) : static
Parameters
- $date : Carbon|DateTimeInterface
Return values
static —setDateTime()
Set the date and time all together
public
setDateTime(int $year, int $month, int $day, int $hour, int $minute, int $second) : static
Parameters
- $year : int
- $month : int
- $day : int
- $hour : int
- $minute : int
- $second : int
Return values
static —setHumanDiffOptions()
public
static setHumanDiffOptions(int $humanDiffOptions) : mixed
Parameters
- $humanDiffOptions : int
Return values
mixed —setLocale()
Set the current translator locale and indicate if the source locale file exists
public
static setLocale(string $locale) : bool
Parameters
- $locale : string
-
locale ex. en
Return values
bool —setMidDayAt()
Set midday/noon hour
public
static setMidDayAt(int $hour) : void
Parameters
- $hour : int
-
midday hour
Return values
void —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([Carbon|string|null $testNow = null ]) : mixed
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.
To clear the test instance call this method using the default parameter of null.
Parameters
- $testNow : Carbon|string|null = null
Return values
mixed —setTimeFrom()
Set the hour, day, and time for this instance to that of the passed instance.
public
setTimeFrom(Carbon|DateTimeInterface $date) : static
Parameters
- $date : Carbon|DateTimeInterface
Return values
static —setTimeFromTimeString()
Set the time by time string
public
setTimeFromTimeString(string $time) : static
Parameters
- $time : string
Return values
static —setTimezone()
Set the instance's timezone from a string or object
public
setTimezone(DateTimeZone|string $value) : static
Parameters
- $value : DateTimeZone|string
Return values
static —setToStringFormat()
Set the default format used when type juggling a Carbon instance to a string
public
static setToStringFormat(string|Closure $format) : void
Parameters
- $format : string|Closure
Return values
void —setTranslator()
Set the translator instance to use
public
static setTranslator(TranslatorInterface $translator) : void
Parameters
- $translator : TranslatorInterface
Return values
void —setUtf8()
Set if UTF8 will be used for localized date/time
public
static setUtf8(bool $utf8) : mixed
Parameters
- $utf8 : bool
Return values
mixed —setWeekendDays()
Set weekend days
public
static setWeekendDays(array<string|int, mixed> $days) : void
Parameters
- $days : array<string|int, mixed>
Return values
void —setWeekEndsAt()
Set the last day of week
public
static setWeekEndsAt(int $day) : void
Parameters
- $day : int
Tags
Return values
void —setWeekStartsAt()
Set the first day of week
public
static setWeekStartsAt(int $day) : void
Parameters
- $day : int
-
week start day
Tags
Return values
void —shouldCompareYearWithMonth()
Get the month comparison default behavior.
public
static shouldCompareYearWithMonth() : bool
Return values
bool —shouldOverflowMonths()
Get the month overflow behavior.
public
static shouldOverflowMonths() : bool
Return values
bool —shouldOverflowYears()
Get the month overflow behavior.
public
static shouldOverflowYears() : bool
Return values
bool —since()
public
since([Carbon|null $other = null ][, bool $absolute = false ][, bool $short = false ][, int $parts = 1 ]) : string
Parameters
- $other : Carbon|null = null
- $absolute : bool = false
-
removes time difference modifiers ago, after, etc
- $short : bool = false
-
displays short format of time units
- $parts : int = 1
-
displays number of parts in the interval
Tags
Return values
string —startOfCentury()
Resets the date to the first day of the century and the time to 00:00:00
public
startOfCentury() : static
Return values
static —startOfDay()
Resets the time to 00:00:00 start of day
public
startOfDay() : static
Return values
static —startOfDecade()
Resets the date to the first day of the decade and the time to 00:00:00
public
startOfDecade() : static
Return values
static —startOfHour()
Modify to start of current hour, minutes and seconds become 0
public
startOfHour() : static
Return values
static —startOfMillennium()
Resets the date to the first day of the century and the time to 00:00:00
public
startOfMillennium() : static
Return values
static —startOfMinute()
Modify to start of current minute, seconds become 0
public
startOfMinute() : static
Return values
static —startOfMonth()
Resets the date to the first day of the month and the time to 00:00:00
public
startOfMonth() : static
Return values
static —startOfQuarter()
Resets the date to the first day of the quarter and the time to 00:00:00
public
startOfQuarter() : static
Return values
static —startOfSecond()
Modify to start of current minute, seconds become 0
public
startOfSecond() : static
Return values
static —startOfWeek()
Resets the date to the first day of week (defined in $weekStartsAt) and the time to 00:00:00
public
startOfWeek() : static
Return values
static —startOfYear()
Resets the date to the first day of the year and the time to 00:00:00
public
startOfYear() : static
Return values
static —subCenturies()
Remove centuries from the instance
public
subCenturies(int $value) : static
Parameters
- $value : int
Return values
static —subCentury()
Remove a century from the instance
public
subCentury([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —subDay()
Remove a day from the instance
public
subDay([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —subDays()
Remove days from the instance
public
subDays(int $value) : static
Parameters
- $value : int
Return values
static —subHour()
Remove an hour from the instance.
public
subHour([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —subHours()
Remove hours from the instance.
public
subHours(int $value) : static
Parameters
- $value : int
Return values
static —subMinute()
Remove a minute from the instance.
public
subMinute([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —subMinutes()
Remove minutes from the instance.
public
subMinutes(int $value) : static
Parameters
- $value : int
Return values
static —subMonth()
Remove a month from the instance
public
subMonth([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —subMonthNoOverflow()
Remove a month with no overflow from the instance
public
subMonthNoOverflow([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —subMonths()
Remove months from the instance
public
subMonths(int $value) : static
Parameters
- $value : int
Return values
static —subMonthsNoOverflow()
Remove months with no overflow from the instance
public
subMonthsNoOverflow(int $value) : static
Parameters
- $value : int
Return values
static —subMonthsWithOverflow()
Remove months from the instance
public
subMonthsWithOverflow(int $value) : static
Parameters
- $value : int
Return values
static —subMonthWithOverflow()
Remove a month from the instance
public
subMonthWithOverflow([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —subQuarter()
Remove a quarter from the instance
public
subQuarter([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —subQuarters()
Remove quarters from the instance
public
subQuarters(int $value) : static
Parameters
- $value : int
Return values
static —subRealHour()
Remove an hour from the instance.
public
subRealHour([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —subRealHours()
Remove hours from the instance using timestamp.
public
subRealHours(int $value) : static
Parameters
- $value : int
Return values
static —subRealMinute()
Remove a minute from the instance using timestamp.
public
subRealMinute([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —subRealMinutes()
Remove a minute from the instance using timestamp.
public
subRealMinutes([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —subRealSecond()
Remove a second from the instance using timestamp.
public
subRealSecond([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —subRealSeconds()
Remove seconds from the instance using timestamp.
public
subRealSeconds(int $value) : static
Parameters
- $value : int
Return values
static —subSecond()
Remove a second from the instance
public
subSecond([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —subSeconds()
Remove seconds from the instance.
public
subSeconds(int $value) : static
Parameters
- $value : int
Return values
static —subWeek()
Remove a week from the instance
public
subWeek([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —subWeekday()
Remove a weekday from the instance
public
subWeekday([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —subWeekdays()
Remove weekdays from the instance
public
subWeekdays(int $value) : static
Parameters
- $value : int
Return values
static —subWeeks()
Remove weeks to the instance
public
subWeeks(int $value) : static
Parameters
- $value : int
Return values
static —subYear()
Remove a year from the instance
public
subYear([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —subYearNoOverflow()
Remove year from the instance with no month overflow
public
subYearNoOverflow([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —subYears()
Remove years from the instance.
public
subYears(int $value) : static
Parameters
- $value : int
Return values
static —subYearsNoOverflow()
Remove years from the instance with no month overflow.
public
subYearsNoOverflow(int $value) : static
Parameters
- $value : int
Return values
static —subYearsWithOverflow()
Remove years from the instance.
public
subYearsWithOverflow(int $value) : static
Parameters
- $value : int
Return values
static —subYearWithOverflow()
Remove year from the instance.
public
subYearWithOverflow([int $value = 1 ]) : static
Parameters
- $value : int = 1
Return values
static —timestamp()
Set the instance's timestamp
public
timestamp(int $value) : static
Parameters
- $value : int
Return values
static —timezone()
Alias for setTimezone()
public
timezone(DateTimeZone|string $value) : static
Parameters
- $value : DateTimeZone|string
Return values
static —to()
Get the difference in a human readable format in the current locale from an other instance given (or now if null given) to current instance.
public
to([Carbon|null $other = null ][, bool $absolute = false ][, bool $short = false ][, int $parts = 1 ]) : 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|null = null
- $absolute : bool = false
-
removes time difference modifiers ago, after, etc
- $short : bool = false
-
displays short format of time units
- $parts : int = 1
-
displays number of parts in the interval
Return values
string —toArray()
Get default array representation
public
toArray() : array<string|int, mixed>
Return values
array<string|int, mixed> —toAtomString()
Format the instance as ATOM
public
toAtomString() : string
Return values
string —toCookieString()
Format the instance as COOKIE
public
toCookieString() : string
Return values
string —toDate()
public
toDate() : DateTime
Tags
Return values
DateTime —toDateString()
Format the instance as date
public
toDateString() : string
Return values
string —toDateTime()
Return native DateTime PHP object matching the current instance.
public
toDateTime() : DateTime
Tags
Return values
DateTime —toDateTimeLocalString()
Format the instance as date and time T-separated with no timezone
public
toDateTimeLocalString() : string
Tags
Return values
string —toDateTimeString()
Format the instance as date and time
public
toDateTimeString() : string
Return values
string —today()
Create a Carbon instance for today.
public
static today([DateTimeZone|string|null $tz = null ]) : static
Parameters
- $tz : DateTimeZone|string|null = null
Return values
static —toDayDateTimeString()
Format the instance with day, date and time
public
toDayDateTimeString() : string
Return values
string —toFormattedDateString()
Format the instance as a readable date
public
toFormattedDateString() : string
Return values
string —toIso8601String()
Format the instance as ISO8601
public
toIso8601String() : string
Return values
string —toIso8601ZuluString()
Convert the instance to UTC and return as Zulu ISO8601
public
toIso8601ZuluString() : string
Return values
string —toISOString()
Return the ISO-8601 string (ex: 1977-04-22T06:00:00Z, if $keepOffset truthy, offset will be kept: 1977-04-22T01:00:00-05:00).
public
toISOString([bool $keepOffset = false ]) : null|string
Parameters
- $keepOffset : bool = false
-
Pass true to keep the date offset. Else forced to UTC.
Tags
Return values
null|string —toJSON()
Return the ISO-8601 string (ex: 1977-04-22T06:00:00Z) with UTC timezone.
public
toJSON() : null|string
Tags
Return values
null|string —tomorrow()
Create a Carbon instance for tomorrow.
public
static tomorrow([DateTimeZone|string|null $tz = null ]) : static
Parameters
- $tz : DateTimeZone|string|null = null
Return values
static —toNow()
Get the difference in a human readable format in the current locale from an other instance given to now
public
toNow([bool $absolute = null ][, bool $short = false ][, int $parts = 1 ]) : string
Parameters
- $absolute : bool = null
-
removes time difference modifiers ago, after, etc
- $short : bool = false
-
displays short format of time units
- $parts : int = 1
-
displays number of parts in the interval
Return values
string —toObject()
Get default object representation.
public
toObject() : object
Tags
Return values
object —toRfc1036String()
Format the instance as RFC1036
public
toRfc1036String() : string
Return values
string —toRfc1123String()
Format the instance as RFC1123
public
toRfc1123String() : string
Return values
string —toRfc2822String()
Format the instance as RFC2822
public
toRfc2822String() : string
Return values
string —toRfc3339String()
Format the instance as RFC3339
public
toRfc3339String() : string
Return values
string —toRfc7231String()
Format the instance as RFC7231
public
toRfc7231String() : string
Return values
string —toRfc822String()
Format the instance as RFC822
public
toRfc822String() : string
Return values
string —toRfc850String()
Format the instance as RFC850
public
toRfc850String() : string
Return values
string —toRssString()
Format the instance as RSS
public
toRssString() : string
Return values
string —toString()
Returns english human readable complete date string.
public
toString() : string
Tags
Return values
string —toTimeString()
Format the instance as time
public
toTimeString() : string
Return values
string —toW3cString()
Format the instance as W3C
public
toW3cString() : string
Return values
string —tz()
Alias for setTimezone()
public
tz(DateTimeZone|string $value) : static
Parameters
- $value : DateTimeZone|string
Return values
static —until()
public
until([Carbon|null $other = null ][, bool $absolute = false ][, bool $short = false ][, int $parts = 1 ]) : string
Parameters
- $other : Carbon|null = null
- $absolute : bool = false
-
removes time difference modifiers ago, after, etc
- $short : bool = false
-
displays short format of time units
- $parts : int = 1
-
displays number of parts in the interval
Tags
Return values
string —useMicrosecondsFallback()
Add microseconds to now on PHP < 7.1 and 7.1.3 if set to true, let microseconds to 0 on those PHP versions if false.
public
static useMicrosecondsFallback([bool $microsecondsFallback = true ]) : mixed
Parameters
- $microsecondsFallback : bool = true
Return values
mixed —useMonthsOverflow()
Indicates if months should be calculated with overflow.
public
static useMonthsOverflow([bool $monthsOverflow = true ]) : void
Parameters
- $monthsOverflow : bool = true
Return values
void —useYearsOverflow()
Indicates if years should be calculated with overflow.
public
static useYearsOverflow([bool $yearsOverflow = true ]) : void
Parameters
- $yearsOverflow : bool = true
Return values
void —year()
Set the instance's year
public
year(int $value) : static
Parameters
- $value : int
Return values
static —yesterday()
Create a Carbon instance for yesterday.
public
static yesterday([DateTimeZone|string|null $tz = null ]) : static
Parameters
- $tz : DateTimeZone|string|null = null
Return values
static —expectDateTime()
Throws an exception if the given object is not a DateTime and does not implement DateTimeInterface and not in $other.
protected
static expectDateTime(mixed $date[, string|array<string|int, mixed> $other = array() ]) : mixed
Parameters
- $date : mixed
- $other : string|array<string|int, mixed> = array()
Tags
Return values
mixed —fixDiffInterval()
protected
static fixDiffInterval(DateInterval $diff, bool $absolute, bool $trimMicroseconds) : CarbonInterval
Parameters
- $diff : DateInterval
- $absolute : bool
- $trimMicroseconds : bool
Return values
CarbonInterval —floatDiffInSeconds()
protected
floatDiffInSeconds(mixed $date) : mixed
Parameters
- $date : mixed
Return values
mixed —resolveCarbon()
Return the Carbon instance passed through, a now instance in the same timezone if null given or parse the input if string given.
protected
resolveCarbon([Carbon|DateTimeInterface|string|null $date = null ]) : static
Parameters
- $date : Carbon|DateTimeInterface|string|null = null
Return values
static —safeCreateDateTimeZone()
Creates a DateTimeZone from a string, DateTimeZone or integer offset.
protected
static safeCreateDateTimeZone(DateTimeZone|string|int|null $object) : DateTimeZone
Parameters
- $object : DateTimeZone|string|int|null
Tags
Return values
DateTimeZone —translator()
Initialize the translator instance if necessary.
protected
static translator() : TranslatorInterface
Return values
TranslatorInterface —createFromFormatAndTimezone()
private
static createFromFormatAndTimezone(mixed $format, mixed $time, mixed $tz) : mixed
Parameters
- $format : mixed
- $time : mixed
- $tz : mixed
Return values
mixed —nextOrPreviousDay()
Go forward or backward to the next week- or weekend-day.
private
nextOrPreviousDay([bool $weekday = true ][, bool $forward = true ]) : $this
Parameters
- $weekday : bool = true
- $forward : bool = true
Return values
$this —setLastErrors()
Set last errors.
private
static setLastErrors(array<string|int, mixed> $lastErrors) : void
Parameters
- $lastErrors : array<string|int, mixed>