Home  >  Article  >  Backend Development  >  How to Check if the Current Date/Time Has Passed a Specific Date/Time in PHP?

How to Check if the Current Date/Time Has Passed a Specific Date/Time in PHP?

DDD
DDDOriginal
2024-10-24 22:05:02945browse

How to Check if the Current Date/Time Has Passed a Specific Date/Time in PHP?

Checking if the Current Date/Time Has Surpassed a Specified Date/Time

In PHP, you can effortlessly use the DateTime class to determine if the present date/time has advanced beyond a specific date/time.

Consider the following example:

<code class="php">if (new DateTime() > new DateTime("2010-05-15 16:00:00")) {
    # The current time exceeds 2010-05-15 16:00:00.
    # In other words, it has passed.
}</code>

This code utilizes the DateTime constructor, where the argument is a string adhering to specific parsing rules. By comparing the current date/time with the specified date/time (05/15/2010 at 4 PM), you can ascertain whether the present time has surpassed the designated moment.

The above is the detailed content of How to Check if the Current Date/Time Has Passed a Specific Date/Time in PHP?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn