What are the different methods available in PHP to manipulate dates and time?
There are several methods available in PHP to manipulate dates and time. Some common methods include using the date() function to format dates, the strtotime() function to convert date strings into timestamps, the DateTime class for more advanced date and time manipulation, and the date_diff() function to calculate the difference between two dates.
// Example: Using the date() function to format dates
$date = date('Y-m-d H:i:s');
echo $date;
```
```php
// Example: Using the strtotime() function to convert date strings into timestamps
$dateString = '2022-01-01';
$timestamp = strtotime($dateString);
echo $timestamp;
```
```php
// Example: Using the DateTime class for more advanced date and time manipulation
$date = new DateTime();
$date->modify('+1 day');
echo $date->format('Y-m-d');
```
```php
// Example: Using the date_diff() function to calculate the difference between two dates
$date1 = new DateTime('2022-01-01');
$date2 = new DateTime('2022-01-10');
$interval = date_diff($date1, $date2);
echo $interval->format('%R%a days');