Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

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
HomeMenu