Google News
logo
PHP Program to Create a date and time from the strtotime() function
In the following example of PHP program to create a date and time from the `strtotime()` function :
Program :
<?php
// create a date and time from a string
$date_str = 'next Sunday 3pm';
$date_time = strtotime($date_str);

// output the formatted date and time
echo date('l, F j, Y \a\t g:i A', $date_time);
?>
Output :
Sunday, May 7, 2023 at 3:00 PM
In this program, we first create a string `$date_str` that contains a date and time representation. We then use the `strtotime()` function to convert this string into a Unix timestamp (number of seconds since the Unix epoch).

We can then use the `date()` function to format this timestamp into a human-readable date and time string. In this example, we use the format string `'l, F j, Y \a\t g:i A'` to output the date and time in the format of `Weekday, Month Day, Year at Hour:Minute AM/PM`.

Note that the `strtotime()` function can parse a wide variety of date and time formats, making it a useful tool for working with dates and times in PHP.