date_interval_create_from_date_string
Description
The date_interval_create_from_date_string of Date / Time for PHP sets up a DateInterval from the relative parts of the string.
Syntax
date_interval_create_from_date_string(string $datetime): DateInterval|false
Parameters
datetime
A date with relative parts. Specifically, the relative formats supported by the parser used for strtotime() and DateTime will be used to construct the DateInterval.
Return
Returns a new DateInterval instance on success, or false on failure.
Examples
1
<? $datetime = "1 day"; $return = date_interval_create_from_date_string($datetime); echo date_interval_format($return, "%d"); ?>
1
2
<? $second = date_interval_create_from_date_string("1 second"); $minute = date_interval_create_from_date_string("1 minute"); $hour = date_interval_create_from_date_string("1 hour"); $day = date_interval_create_from_date_string("1 day"); $week = date_interval_create_from_date_string("1 week"); $month = date_interval_create_from_date_string("1 month"); $year = date_interval_create_from_date_string("1 year"); $format = "Y-m-d H:i:s"; $date = date_create(); echo date_format($date, $format) . PHP_EOL; $date = date_create(); date_add($date, $second); echo date_format($date, $format) . PHP_EOL; $date = date_create(); date_add($date, $minute); echo date_format($date, $format) . PHP_EOL; $date = date_create(); date_add($date, $hour); echo date_format($date, $format) . PHP_EOL; $date = date_create(); date_add($date, $day); echo date_format($date, $format) . PHP_EOL; $date = date_create(); date_add($date, $week); echo date_format($date, $format) . PHP_EOL; $date = date_create(); date_add($date, $month); echo date_format($date, $format) . PHP_EOL; $date = date_create(); date_add($date, $year); echo date_format($date, $format); ?>
2024-10-14 12:25:24 2024-10-14 12:25:25 2024-10-14 12:26:24 2024-10-14 13:25:24 2024-10-15 12:25:24 2024-10-21 12:25:24 2024-11-14 12:25:24 2025-10-14 12:25:24
Links
Date / Time
- checkdate
- date
- date_add
- date_create
- date_create_from_format
- date_create_immutable
- date_create_immutable_from_format
- date_date_set
- date_default_timezone_get
- date_default_timezone_set
- date_diff
- date_format
- date_get_last_errors
- date_interval_format
- date_isodate_set
- date_modify
- date_offset_get
- date_parse
- date_parse_from_format
- date_sub
- date_sun_info
- date_sunrise
- date_sunset
- date_time_set
- date_timestamp_get
- date_timestamp_set
- date_timezone_get
- date_timezone_set
- getdate
- gettimeofday
- gmdate
- gmmktime
- gmstrftime
- idate
- localtime
- microtime
- mktime
- strftime
- strptime
- strtotime
- time
- timezone_abbreviations_list
- timezone_identifiers_list
- timezone_location_get
- timezone_name_from_abbr
- timezone_name_get
- timezone_offset_get
- timezone_open
- timezone_transitions_get
- timezone_version_get