fyre / datetime
A DateTime library.
Installs: 461
Dependents: 7
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 0
pkg:composer/fyre/datetime
Requires
- fyre/macro: ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.59
- fyre/php-cs-fixer-config: ^1.0
- phpunit/phpunit: ^12
This package is auto-updated.
Last update: 2025-11-02 10:12:18 UTC
README
FyreDateTime is a free, open-source immutable date manipulation library for PHP.
It is a modern library, and features support for ICU formats, time zones and locales.
Table Of Contents
- Installation
- Basic Usage
- Date Creation
- Date Formatting
- Date Attributes
- Week Attributes
- Time Attributes
- Timestamps
- Time Zones
- Locales
- Manipulation
- Comparisons
- Utility Methods
- Static Methods
Installation
Using Composer
composer require fyre/datetime
In PHP:
use Fyre\DateTime\DateTime;
Basic Usage
$dateStringis a string representing the date, and will default to the current timestamp.$timeZoneis a string representing the time zone of the date, and will default to the system time zone.$localeis a string representing the locale of the date, and will default to the system locale.
$dateTime = new DateTime($dateString, $timeZone, $locale);
Date Creation
Create From Array
$dateArrayis an array containing the year, month, date, hours, minutes, seconds and milliseconds.$timeZoneis a string representing the time zone of the date, and will default to the system time zone.$localeis a string representing the locale of the date, and will default to the system locale.
$dateTime = DateTime::createFromArray($dateArray, $timeZone, $locale);
The month and date in the $dateArray will default to 1 if not set. The hours, minutes, seconds and milliseconds will default to 0.
Create From Format
$formatStringis a string containing the format you wish to use for parsing.$dateStringis a string representing the date you are parsing.$timeZoneis a string representing the time zone of the date, and will default to the system time zone.$localeis a string representing the locale of the date, and will default to the system locale.
The $formatString supports tokens described in the ICU specification.
$dateTime = DateTime::createFromFormat($formatString, $dateString, $timeZone, $locale);
Create From Iso String
$dateStringis a string representing the date you are parsing.$timeZoneis a string representing the time zone of the date, and will default to the system time zone.$localeis a string representing the locale of the date, and will default to the system locale.
$dateTime = DateTime::createFromIsoString($dateString, $timeZone, $locale);
Create From Native DateTime
$dateTimeis an instance of a class implementing DateTimeInterface.$timeZoneis a string representing the time zone of the date, and will default to the system time zone.$localeis a string representing the locale of the date, and will default to the system locale.
$newDateTime = DateTime::createFromNativeDateTime($dateTime, $timeZone, $locale);
Create From Timestamp
$timestampis the number of seconds since the UNIX epoch.$timeZoneis a string representing the time zone of the date, and will default to the system time zone.$localeis a string representing the locale of the date, and will default to the system locale.
$dateTime = DateTime::createFromTimestamp($timestamp, $timeZone, $locale);
Now
$timeZoneis a string representing the time zone of the date, and will default to the system time zone.$localeis a string representing the locale of the date, and will default to the system locale.
$dateTime = DateTime::now($timeZone, $locale);
Date Formatting
Format
Once you have created a DateTime object, you can get a string representation using a specific format with the format method.
$formatStringis a string containing the format you wish to output using.
The $formatString supports tokens described in the ICU specification.
$dateString = $dateTime->format($formatString);
To String
Format the current date using "eee MMM dd yyyy HH:mm:ss xx (VV)".
$string = $dateTime->toString();
To Date String
Format the current date using "eee MMM dd yyyy".
$dateString = $dateTime->toDateString();
To Iso String
Format the current date using "yyyy-MM-dd'T'HH:mm:ss.SSSxxx" (in English and UTC time zone).
$isoString = $dateTime->toIsoString();
To Native DateTime
Convert the object to a native DateTime.
$nativeDateTime = $dateTime->toNativeDateTime();
To Time String
Format the current date using "HH:mm:ss xx (VV)".
$timeString = $dateTime->toTimeString();
To UTC String
Format the current date using "eee MMM dd yyyy HH:mm:ss xx (VV)" (in UTC time zone).
$utcString = $dateTime->toUTCString();
Date Attributes
Get Date
Get the date in current time zone.
$date = $dateTime->getDate();
Get Day
Get the day of the week in current time zone.
The $day returned will be between 0 (Sunday) and 6 (Saturday).
$day = $dateTime->getDay();
Get Day Of Year
Get the day of the year in current time zone.
The $dayOfYear returned will be between 0 and 365.
$dayOfYear = $dateTime->getDayOfYear();
Get Month
Get the month in current time zone.
The $month returned will be between 1 (January) and 12 (December).
$month = $dateTime->getMonth();
Get Quarter
Get the quarter of the year in current time zone.
The $quarter returned will be between 1 and 4.
$quarter = $dateTime->getQuarter();
Get Year
Get the year in current time zone.
$year = $dateTime->getYear();
With Date
Clone the DateTime with a new date in current time zone.
$dateis a number representing the date.
$newDate = $dateTime->withDate($date);
With Day
Clone the DateTime with a new day of the week in current time zone.
$dayis a number representing the day of the week (between 0 and 6).
$newDateTime = $dateTime->withDay($day);
With Day Of Year
Clone the DateTime with a new day of the year in current time zone.
$dayOfYearis a number representing the day of the year (between 0 and 365).
$newDateTime = $dateTime->withDayOfYear($dayOfYear);
With Month
Clone the DateTime with a new month in current time zone.
$monthis a number representing the month (between 1 and 12).$dateis a number representing the date, and will default to the current value.
If the $date argument is omitted, and the new month contains less days than the current date, the date will be set to the last day of the new month.
To disable date clamping, use the method DateTime::setDateClamping() using false as the argument.
$newDateTime = $dateTime->withMonth($month, $date);
With Quarter
Clone the DateTime with a new quarter of the year in current time zone.
$quarteris a number representing the quarter between 1 and 4.
$newDateTime = $dateTime->withQuarter($quarter);
With Year
Clone the DateTime with a new year in current time zone.
$yearis a number representing the year.$monthis a number representing the month (between 1 and 12), and will default to the current value.$dateis a number representing the date, and will default to the current value.
If the $date argument is omitted, and the new month contains less days than the current date, the date will be set to the last day of the new month.
To disable date clamping, use the method DateTime::setDateClamping() using false as the argument.
$newDateTime = $dateTime->withYear($year, $month, $date);
Week Attributes
Get Week
Get the week of the year in current time zone.
The $week returned will be between 1 and 53 (week starting on Monday).
$week = $dateTime->getWeek();
Get Week Day
Get the local day of the week in current time zone.
The $weekDay returned will be between 1 and 7.
$weekDay = $dateTime->getWeekDay();
Get Week Day In Month
Get the day of the week in the month, in current time zone.
The $weekDayInMonth returned will be between 1 and 5.
$weekDayInMonth = $dateTime->getWeekDayInMonth();
Get Week Of Month
Get the week of the month in current time zone.
The $weekOfMonth returned will be between 1 and 5.
$weekOfMonth = $dateTime->getWeekOfMonth();
Get Week Year
Get the week year in current time zone.
This method is identical to getYear() except in cases where the week belongs to the previous or next year, then that value will be used instead.
$weekYear = $dateTime->getWeekYear();
With Week
Clone the DateTime with a new week in current time zone.
$weekis a number representing the week.$weekDayis a number representing the day (between 1 and 7), and will default to the current value.
$newDateTime = $dateTime->withWeek($week, $weekDay);
With Week Day
Clone the DateTime with a new local day of the week in current time zone.
$weekDayis a number representing the week day (between 1 and 7).
$newDateTime = $dateTime->withWeekDay($weekDay);
With Week Day In Month
Clone the DateTime with a new day of the week in the month, in current time zone.
$weekDayInMonthis a number representing the day of the week in month (between 1 and 5).
$newDateTime = $dateTime->withWeekDayInMonth($weekDayInMonth);
With Week Of Month
Clone the DateTime with a new week of the month in current time zone.
$weekOfMonthis a number representing the week of the month (between 1 and 5).
$newDateTime = $dateTime->withWeekOfMonth($weekOfMonth);
With Week Year
Clone the DateTime with a new week year in current time zone.
$weekYearis a number representing the year.$weekis a number representing the week, and will default to the current value.$weekDayis a number representing the day (between 1 and 7), and will default to the current value.
$newDateTime = $dateTime->withWeekYear($weekYear, $week, $weekDay);
Time Attributes
Get Hours
Get the hours of the day in current time zone.
The $hours returned will be between 0 and 23.
$hours = $dateTime->getHours();
Get Milliseconds
Get the milliseconds of the second in current time zone.
The $milliseconds returned will be between 0 and 999.
$milliseconds = $dateTime->getMilliseconds();
Get Minutes
Get the minutes of the hour in current time zone.
The $minutes returned will be between 0 and 59.
$minutes = $dateTime->getMinutes();
Get Seconds
Get the seconds of the minute in current time zone.
The $seconds returned will be between 0 and 59.
$seconds = $dateTime->getSeconds();
With Hours
Clone the DateTime with a new hours of the day in current time zone.
$hoursis a number representing the hours of the day (between 0 and 23).$minutesis a number representing the minutes of the hour (between 0 and 59), and will default to the current value.$secondsis a number representing the seconds of the minute (between 0 and 59), and will default to the current value.$millisecondsis a number representing the milliseconds of the second (between 0 and 999), and will default to the current value.
$newDateTime = $dateTime->withHours($hours, $minutes, $seconds, $milliseconds);
With Milliseconds
Clone the DateTime with a new milliseconds of the second in current time zone.
$millisecondsis a number representing the milliseconds of the second (between 0 and 999).
$newDateTime = $dateTime->withMilliseconds($milliseconds);
With Minutes
Clone the DateTime with a new minutes of the hour in current time zone.
$minutesis a number representing the minutes of the hour (between 0 and 59).$secondsis a number representing the seconds of the minute (between 0 and 59), and will default to the current value.$millisecondsis a number representing the milliseconds of the second (between 0 and 999), and will default to the current value.
$newDateTime = $dateTime->withMinutes($minutes, $seconds, $milliseconds);
With Seconds
Clone the DateTime with a new seconds of the minute in current time zone.
$secondsis a number representing the seconds of the minute (between 0 and 59).$millisecondsis a number representing the milliseconds of the second (between 0 and 999), and will default to the current value.
$newDateTime = $dateTime->withSeconds($seconds, $milliseconds);
Timestamps
Get Milliseconds
Get the number of milliseconds since the UNIX epoch.
$time = $dateTime->getTime();
Get Seconds
Get the number of seconds since the UNIX epoch.
$timestamp = $dateTime->getTimestamp();
With Milliseconds
Clone the DateTime with a new number of milliseconds since the UNIX epoch.
$newDateTime = $dateTime->withTime($time);
With Seconds
Clone the DateTime with a new number of seconds since the UNIX epoch.
$newDateTime = $dateTime->withTimestamp($timestamp);
Time Zones
Get Time Zone
Get the name of the current time zone.
$timeZone = $dateTime->getTimeZone();
Get Time Zone Offset
Get the UTC offset (in minutes) of the current time zone.
$offset = $dateTime->getTimeZoneOffset();
With Time Zone
Clone the DateTime with a new time zone.
$timeZoneis the name of the new time zone, which can be either "UTC", a supported value from the IANA timeZone database or an offset string.
$newDateTime = $dateTime->withTimeZone($timeZone);
With Time Zone Offset
Clone the DateTime with a new UTC offset (in minutes).
$offsetis the UTC offset (in minutes).
$newDateTime = $dateTime->withTimeZoneOffset($offset);
Locales
Get Locale
Get the name of the current locale.
$locale = $dateTime->getLocale();
With Locale
Clone the DateTime with a new locale.
$localeis the name of the new locale.
$newDateTime = $dateTime->withLocale($locale);
Manipulation
Add Day
Add a day to the current date.
$newDateTime = $dateTime->addDay();
Add Days
Add days to the current date.
$amountis a number representing the amount of days to add.
$newDateTime = $dateTime->addDay($amount);
Add Hour
Add a hour to the current date.
$newDateTime = $dateTime->addHour();
Add Hours
Add hours to the current date.
$amountis a number representing the amount of hours to add.
$newDateTime = $dateTime->addHours($amount);
Add Minute
Add a minute to the current date.
$newDateTime = $dateTime->addMinute();
Add Minutes
Add minutes to the current date.
$amountis a number representing the amount of minutes to add.
$newDateTime = $dateTime->addMinutes($amount);
Add Month
Add a month to the current date.
$newDateTime = $dateTime->addMonth();
Add Months
Add months to the current date.
$amountis a number representing the amount of months to add.
$newDateTime = $dateTime->addMonths($amount);
Add Second
Add a second to the current date.
$newDateTime = $dateTime->addSecond();
Add Seconds
Add seconds to the current date.
$amountis a number representing the amount of seconds to add.
$newDateTime = $dateTime->addSeconds($amount);
Add Week
Add a week to the current date.
$newDateTime = $dateTime->addWeek();
Add Weeks
Add weeks to the current date.
$amountis a number representing the amount of weeks to add.
$newDateTime = $dateTime->addWeeks($amount);
Add Year
Add a year to the current date.
$newDateTime = $dateTime->addYear();
Add Years
Add years to the current date.
$amountis a number representing the amount of years to add.
$newDateTime = $dateTime->addYears($amount);
End Of Day
Set the date to the end of the day in current time zone.
$newDateTime = $dateTime->endOfDay();
End Of Hour
Set the date to the end of the hour in current time zone.
$newDateTime = $dateTime->endOfHour();
End Of Minute
Set the date to the end of the minute in current time zone.
$newDateTime = $dateTime->endOfMinute();
End Of Month
Set the date to the end of the month in current time zone.
$newDateTime = $dateTime->endOfMonth();
End Of Quarter
Set the date to the end of the quarter in current time zone.
$newDateTime = $dateTime->endOfQuarter();
End Of Second
Set the date to the end of the second in current time zone.
$newDateTime = $dateTime->endOfSecond();
End Of Week
Set the date to the end of the week in current time zone.
$newDateTime = $dateTime->endOfWeek();
End Of Year
Set the date to the end of the year in current time zone.
$newDateTime = $dateTime->endOfYear();
Start Of Day
Set the date to the start of the day in current time zone.
$newDateTime = $dateTime->startOfDay();
Start Of Hour
Set the date to the start of the hour in current time zone.
$newDateTime = $dateTime->startOfHour();
Start Of Minute
Set the date to the start of the minute in current time zone.
$newDateTime = $dateTime->startOfMinute();
Start Of Month
Set the date to the start of the month in current time zone.
$newDateTime = $dateTime->startOfMonth();
Start Of Quarter
Set the date to the start of the quarter in current time zone.
$newDateTime = $dateTime->startOfQuarter();
Start Of Second
Set the date to the start of the second in current time zone.
$newDateTime = $dateTime->startOfSecond();
Start Of Week
Set the date to the start of the week in current time zone.
$newDateTime = $dateTime->startOfWeek();
Start Of Year
Set the date to the start of the year in current time zone.
$newDateTime = $dateTime->startOfYear();
Subtract Day
Subtract a day to the current date.
$newDateTime = $dateTime->subtractDay();
Subtract Days
Subtract days to the current date.
$amountis a number representing the amount of days to subtract.
$newDateTime = $dateTime->subtractDay($amount);
Subtract Hour
Subtract a hour to the current date.
$newDateTime = $dateTime->subtractHour();
Subtract Hours
Subtract hours to the current date.
$amountis a number representing the amount of hours to subtract.
$newDateTime = $dateTime->subtractHours($amount);
Subtract Minute
Subtract a minute to the current date.
$newDateTime = $dateTime->subtractMinute();
Subtract Minutes
Subtract minutes to the current date.
$amountis a number representing the amount of minutes to subtract.
$newDateTime = $dateTime->subtractMinutes($amount);
Subtract Month
Subtract a month to the current date.
$newDateTime = $dateTime->subtractMonth();
Subtract Months
Subtract months to the current date.
$amountis a number representing the amount of months to subtract.
$newDateTime = $dateTime->subtractMonths($amount);
Subtract Second
Subtract a second to the current date.
$newDateTime = $dateTime->subtractSecond();
Subtract Seconds
Subtract seconds to the current date.
$amountis a number representing the amount of seconds to subtract.
$newDateTime = $dateTime->subtractSeconds($amount);
Subtract Week
Subtract a week to the current date.
$newDateTime = $dateTime->subtractWeek();
Subtract Weeks
Subtract weeks to the current date.
$amountis a number representing the amount of weeks to subtract.
$newDateTime = $dateTime->subtractWeeks($amount);
Subtract Year
Subtract a year to the current date.
$newDateTime = $dateTime->subtractYear();
Subtract Years
Subtract years to the current date.
$amountis a number representing the amount of years to subtract.
$newDateTime = $dateTime->subtractYears($amount);
Comparisons
Difference
Get the difference between two dates in milliseconds.
$otheris the DateTime object to compare to.
$diff = $dateTime->diff($other);
Difference In Days
Get the difference between two dates in days.
$otheris the DateTime object to compare to.$relativeis a boolean indicating whether to return the relative difference, and will default to true.
$diff = $dateTime->diffInDays($other, $relative);
If $relative is true (default) the value returned will be the relative difference, ignoring higher precision properties.
Difference In Hours
Get the difference between two dates in hours.
$otheris the DateTime object to compare to.$relativeis a boolean indicating whether to return the relative difference, and will default to true.
$diff = $dateTime->diffInHours($other, $relative);
If $relative is true (default) the value returned will be the relative difference, ignoring higher precision properties.
Difference In Minutes
Get the difference between two dates in minutes.
$otheris the DateTime object to compare to.$relativeis a boolean indicating whether to return the relative difference, and will default to true.
$diff = $dateTime->diffInMinutes($other, $relative);
If $relative is true (default) the value returned will be the relative difference, ignoring higher precision properties.
Difference In Months
Get the difference between two dates in months.
$otheris the DateTime object to compare to.$relativeis a boolean indicating whether to return the relative difference, and will default to true.
$diff = $dateTime->diffInMonths($other, $relative);
If $relative is true (default) the value returned will be the relative difference, ignoring higher precision properties.
Difference In Seconds
Get the difference between two dates in seconds.
$otheris the DateTime object to compare to.$relativeis a boolean indicating whether to return the relative difference, and will default to true.
$diff = $dateTime->diffInSeconds($other, $relative);
If $relative is true (default) the value returned will be the relative difference, ignoring higher precision properties.
Difference In Weeks
Get the difference between two dates in weeks.
$otheris the DateTime object to compare to.$relativeis a boolean indicating whether to return the relative difference, and will default to true.
$diff = $dateTime->diffInWeeks($other, $relative);
If $relative is true (default) the value returned will be the relative difference, ignoring higher precision properties.
Difference In Years
Get the difference between two dates in years.
$otheris the DateTime object to compare to.$relativeis a boolean indicating whether to return the relative difference, and will default to true.
$diff = $dateTime->diffInYears($other, $relative);
If $relative is true (default) the value returned will be the relative difference, ignoring higher precision properties.
Is After?
Determine whether the DateTime is after another date.
$otheris the DateTime object to compare to.
$isAfter = $dateTime->isAfter($other);
Is After Day?
Determine whether the DateTime is after another date (comparing by day).
$otheris the DateTime object to compare to.
$isAfter = $dateTime->isAfterDay($other);
Is After Hour?
Determine whether the DateTime is after another date (comparing by hour).
$otheris the DateTime object to compare to.
$isAfter = $dateTime->isAfterHour($other);
Is After Minute?
Determine whether the DateTime is after another date (comparing by minute).
$otheris the DateTime object to compare to.
$isAfter = $dateTime->isAfterMinute($other);
Is After Month?
Determine whether the DateTime is after another date (comparing by month).
$otheris the DateTime object to compare to.
$isAfter = $dateTime->isAfterMonth($other);
Is After Second?
Determine whether the DateTime is after another date (comparing by second).
$otheris the DateTime object to compare to.
$isAfter = $dateTime->isAfterSecond($other);
Is After Week?
Determine whether the DateTime is after another date (comparing by week).
$otheris the DateTime object to compare to.
$isAfter = $dateTime->isAfterWeek($other);
Is After Year?
Determine whether the DateTime is after another date (comparing by year).
$otheris the DateTime object to compare to.
$isAfter = $dateTime->isAfterYear($other);
Is Before?
Determine whether the DateTime is before another date.
$otheris the DateTime object to compare to.
$isBefore = $dateTime->isBefore($other);
Is Before Day?
Determine whether the DateTime is before another date (comparing by day).
$otheris the DateTime object to compare to.
$isBefore = $dateTime->isBeforeDay($other);
Is Before Hour?
Determine whether the DateTime is before another date (comparing by hour).
$otheris the DateTime object to compare to.
$isBefore = $dateTime->isBeforeHour($other);
Is Before Minute?
Determine whether the DateTime is before another date (comparing by minute).
$otheris the DateTime object to compare to.
$isBefore = $dateTime->isBeforeMinute($other);
Is Before Month?
Determine whether the DateTime is before another date (comparing by month).
$otheris the DateTime object to compare to.
$isBefore = $dateTime->isBeforeMonth($other);
Is Before Second?
Determine whether the DateTime is before another date (comparing by second).
$otheris the DateTime object to compare to.
$isBefore = $dateTime->isBeforeSecond($other);
Is Before Week?
Determine whether the DateTime is before another date (comparing by week).
$otheris the DateTime object to compare to.
$isBefore = $dateTime->isBeforeWeek($other);
Is Before Year?
Determine whether the DateTime is before another date (comparing by year).
$otheris the DateTime object to compare to.
$isBefore = $dateTime->isBeforeYear($other);
Is Between?
Determine whether the DateTime is between two other dates.
$startis the starting DateTime object to compare to.$endis the ending DateTime object to compare to.
$isBetween = $dateTime->isBetween($start, $end);
Is Between Day?
Determine whether the DateTime is between two other dates (comparing by day).
$startis the starting DateTime object to compare to.$endis the ending DateTime object to compare to.
$isBetween = $dateTime->isBetweenDay($start, $end);
Is Between Hour?
Determine whether the DateTime is between two other dates (comparing by hour).
$startis the starting DateTime object to compare to.$endis the ending DateTime object to compare to.
$isBetween = $dateTime->isBetweenHour($start, $end);
Is Between Minute?
Determine whether the DateTime is between two other dates (comparing by minute).
$startis the starting DateTime object to compare to.$endis the ending DateTime object to compare to.
$isBetween = $dateTime->isBetweenMinute($start, $end);
Is Between Month?
Determine whether the DateTime is between two other dates (comparing by month).
$startis the starting DateTime object to compare to.$endis the ending DateTime object to compare to.
$isBetween = $dateTime->isBetweenMonth($start, $end);
Is Between Second?
Determine whether the DateTime is between two other dates (comparing by second).
$startis the starting DateTime object to compare to.$endis the ending DateTime object to compare to.
$isBetween = $dateTime->isBetweenSecond($start, $end);
Is Between Week?
Determine whether the DateTime is between two other dates (comparing by week).
$startis the starting DateTime object to compare to.$endis the ending DateTime object to compare to.
$isBetween = $dateTime->isBetweenWeek($start, $end);
Is Between Year?
Determine whether the DateTime is between two other dates (comparing by year).
$startis the starting DateTime object to compare to.$endis the ending DateTime object to compare to.
$isBetween = $dateTime->isBetweenYear($start, $end);
Is Same?
Determine whether the DateTime is the same as another date.
$otheris the DateTime object to compare to.
$isSame = $dateTime->isSame($other);
Is Same Day?
Determine whether the DateTime is the same as another date (comparing by day).
$otheris the DateTime object to compare to.
$isSame = $dateTime->isSameDay($other);
Is Same Hour?
Determine whether the DateTime is the same as another date (comparing by hour).
$otheris the DateTime object to compare to.
$isSame = $dateTime->isSameHour($other);
Is Same Minute?
Determine whether the DateTime is the same as another date (comparing by minute).
$otheris the DateTime object to compare to.
$isSame = $dateTime->isSameMinute($other);
Is Same Month?
Determine whether the DateTime is the same as another date (comparing by month).
$otheris the DateTime object to compare to.
$isSame = $dateTime->isSameMonth($other);
Is Same Second?
Determine whether the DateTime is the same as another date (comparing by second).
$otheris the DateTime object to compare to.
$isSame = $dateTime->isSameSecond($other);
Is Same Week?
Determine whether the DateTime is the same as another date (comparing by week).
$otheris the DateTime object to compare to.
$isSame = $dateTime->isSameWeek($other);
Is Same Year?
Determine whether the DateTime is the same as another date (comparing by year).
$otheris the DateTime object to compare to.
$isSame = $dateTime->isSameYear($other);
Is Same Or After?
Determine whether the DateTime is the same as or after another date.
$otheris the DateTime object to compare to.
$isSameOrAfter = $dateTime->isSameOrAfter($other);
Is Same Or After Day?
Determine whether the DateTime is the same as or after another date (comparing by day).
$otheris the DateTime object to compare to.
$isSameOrAfter = $dateTime->isSameOrAfterDay($other);
Is Same Or After Hour?
Determine whether the DateTime is the same as or after another date (comparing by hour).
$otheris the DateTime object to compare to.
$isSameOrAfter = $dateTime->isSameOrAfterHour($other);
Is Same Or After Minute?
Determine whether the DateTime is the same as or after another date (comparing by minute).
$otheris the DateTime object to compare to.
$isSameOrAfter = $dateTime->isSameOrAfterMinute($other);
Is Same Or After Month?
Determine whether the DateTime is the same as or after another date (comparing by month).
$otheris the DateTime object to compare to.
$isSameOrAfter = $dateTime->isSameOrAfterMonth($other);
Is Same Or After Second?
Determine whether the DateTime is the same as or after another date (comparing by second).
$otheris the DateTime object to compare to.
$isSameOrAfter = $dateTime->isSameOrAfterSecond($other);
Is Same Or After Week?
Determine whether the DateTime is the same as or after another date (comparing by week).
$otheris the DateTime object to compare to.
$isSameOrAfter = $dateTime->isSameOrAfterWeek($other);
Is Same Or After Year?
Determine whether the DateTime is the same as or after another date (comparing by year).
$otheris the DateTime object to compare to.
$isSameOrAfter = $dateTime->isSameOrAfterYear($other);
Is Same Or Before?
Determine whether the DateTime is the same as or before another date.
$otheris the DateTime object to compare to.
$isSameOrBefore = $dateTime->isSameOrBefore($other);
Is Same Or Before Day?
Determine whether the DateTime is the same as or before another date (comparing by day).
$otheris the DateTime object to compare to.
$isSameOrBefore = $dateTime->isSameOrBeforeDay($other);
Is Same Or Before Hour?
Determine whether the DateTime is the same as or before another date (comparing by hour).
$otheris the DateTime object to compare to.
$isSameOrBefore = $dateTime->isSameOrBeforeHour($other);
Is Same Or Before Minute?
Determine whether the DateTime is the same as or before another date (comparing by minute).
$otheris the DateTime object to compare to.
$isSameOrBefore = $dateTime->isSameOrBeforeMinute($other);
Is Same Or Before Month?
Determine whether the DateTime is the same as or before another date (comparing by month).
$otheris the DateTime object to compare to.
$isSameOrBefore = $dateTime->isSameOrBeforeMonth($other);
Is Same Or Before Second?
Determine whether the DateTime is the same as or before another date (comparing by second).
$otheris the DateTime object to compare to.
$isSameOrBefore = $dateTime->isSameOrBeforeSecond($other);
Is Same Or Before Week?
Determine whether the DateTime is the same as or before another date (comparing by week).
$otheris the DateTime object to compare to.
$isSameOrBefore = $dateTime->isSameOrBeforeWeek($other);
Is Same Or Before Year?
Determine whether the DateTime is the same as or before another date (comparing by year).
$otheris the DateTime object to compare to.
$isSameOrBefore = $dateTime->isSameOrBeforeYear($other);
Utility Methods
Day Name
Get the name of the day of the week in current time zone and locale.
$typecan be either "long", "short" or "narrow", and will default to "long" if it is not set.
$dayName = $dateTime->dayName($type);
Day Period
Get the day period in current time zone and locale.
$typecan be either "long" or "short", and will default to "long" if it is not set.
$dayPeriod = $dateTime->dayPeriod($type);
Days In Month
Get the number of days in the current month.
$daysInMonth = $dateTime->daysInMonth();
Days In Year
Get the number of days in the current year.
$daysInYear = $dateTime->daysInYear();
Era
Get the era in current time zone and locale.
$typecan be either "long", "short" or "narrow", and will default to "long" if it is not set.
$era = $dateTime->era($type);
Is DST?
Determine whether the DateTime is in daylight savings.
$isDst = $dateTime->isDst();
Is Leap Year?
Determine whether the year is a leap year.
$isLeapYear = $dateTime->isLeapYear();
Month Name
Get the name of the month in current time zone and locale.
$typecan be either "long", "short" or "narrow", and will default to "long" if it is not set.
$monthName = $dateTime->monthName($type);
Time Zone Name
Get the name of the current time zone and locale.
$typecan be either "long" or "short", and will default to "long" if it is not set.
$timeZoneName = $dateTime->timeZoneName($type);
Weeks In Year
Get the number of weeks in the current year.
$weeksInYear = $dateTime->weeksInYear();
Static Methods
Get Default Locale
Get the default locale.
$locale = DateTime::getDefaultLocale();
Get Default Time Zone
Get the default time zone.
$timeZone = DateTime::getDefaultTimeZone();
Set Date Clamping
Set whether dates will be clamped when changing months.
$clampDatesis a boolean indicating whether to clamp dates.
DateTime::setDateClamping($clampDates);
Set Default Locale
Set the default locale.
$localeis the locale.
DateTime::setDefaultLocale($locale);
Set Default Time Zone
Set the default time zone.
$timeZoneis the time zone, which can be either "UTC", a supported value from the IANA time zone database, or an offset string.
DateTime::setDefaultTimeZone($timeZone);