DateTime
class DateTime
Supports ability to manipulate how time is displayed. Most functions are wrappers for those found in the Carbon class.
Constants
| FORMAT_12_HOUR |
12 hour format. |
| FORMAT_24_HOUR |
24 hour format. |
| FORMAT_HUMAN_READABLE |
Human readable format. |
| FORMAT_DATE_ONLY |
Date only. |
| FORMAT_TIME_ONLY_12H |
Time only in 12 hour format |
| FORMAT_TIME_ONLY_24H |
Time only in 24 hour format |
| FORMAT_FRIENDLY_DATE |
Friendly date format. |
| FORMAT_DAY_DATE |
Day date format. |
| FORMAT_ISO_8601 |
ISO 8601 format. |
| FORMAT_RFC_2822 |
RFC 2822 format. |
| FORMAT_SQL_DATETIME |
SQL DateTime format. |
Methods
Returns string that describes time. The results can be set using constants, locale, and timezone.
Adds second passed as parameter to current time.
Accepts UTC time in format Y-m-d H:i:s and returns a string describing how much time has elapsed.
Shows the difference between two times. An example is shown below: DateTimeHelper::timeDifference('2025-03-09 08:00:00', '2025-03-09 15:30:45'); Output: "7 hours before"
Generates a timestamp.
Converts to ISO 8610 format.
Details
at line 45
static string
formatTime(string $time, string $format = self::FORMAT_12_HOUR, string $locale = 'en', string $timezone = 'UTC')
Returns string that describes time. The results can be set using constants, locale, and timezone.
at line 58
static string
nowPlusSeconds(int $seconds)
Adds second passed as parameter to current time.
at line 79
static string
timeAgo(string $time, string $locale = 'en', string $timezone = 'UTC', bool $short = false)
Accepts UTC time in format Y-m-d H:i:s and returns a string describing how much time has elapsed.
This function supports a short form with the following example: DateTime::timeAgo($user->updated_at, 'en', 'UTC', true);
This will show something like 21m.
at line 99
static string
timeDifference(string $startTime, string $endTime, string $timezone = 'UTC')
Shows the difference between two times. An example is shown below: DateTimeHelper::timeDifference('2025-03-09 08:00:00', '2025-03-09 15:30:45'); Output: "7 hours before"
at line 110
static string
timeStamps()
Generates a timestamp.
at line 122
static string
toISO8601(string $time, string $timezone = 'UTC')
Converts to ISO 8610 format.