Google News
logo
PHP Program to Create more dates/times from strtotime()
In the following example of PHP program that uses the `strtotime()` function to create more dates/times :
Program :
<?php
// Create a date/time for 3 days from now
$date1 = strtotime("+3 days");
echo "3 days from now: " . date("Y-m-d H:i:s", $date1) . "\n";

// Create a date/time for 2 weeks ago
$date2 = strtotime("-2 weeks");
echo "2 weeks ago: " . date("Y-m-d H:i:s", $date2) . "\n";

// Create a date/time for the last day of next month
$date3 = strtotime("last day of next month");
echo "Last day of next month: " . date("Y-m-d H:i:s", $date3) . "\n";

// Create a date/time for the first Monday of next month
$date4 = strtotime("first Monday of next month");
echo "First Monday of next month: " . date("Y-m-d H:i:s", $date4) . "\n";
?>
Output :
3 days from now: 2023-05-04 10:43:22
2 weeks ago: 2023-04-17 10:43:22
Last day of next month: 2023-06-30 10:43:22
First Monday of next month: 2023-06-05 00:00:00
In this example, the `strtotime()` function is used to create a timestamp for various dates/times relative to the current date/time.

The `date()` function is then used to format these timestamps as strings in a human-readable format.