How to create a DateTime object with a specific date and time in PHP?

To create a DateTime object with a specific date and time in PHP, you can use the DateTime constructor, passing in the desired date and time in the format you want. Here is an example:

$specificDateTime = new DateTime('2022-12-31 18:30:00');

You can replace '2022-12-31 18:30:00' with your desired date and time. The format should be 'YYYY-MM-DD HH:MM:SS' (year, month, day, hour, minute, second).

Alternatively, you can also use the createFromFormat method to create a DateTime object with a specific format. Here is an example:

$specificDateTime = DateTime::createFromFormat('Y-m-d H:i:s', '2022-12-31 18:30:00');

Again, you can replace '2022-12-31 18:30:00' with your desired date and time, and modify the format string ('Y-m-d H:i:s') if needed.