Home >Backend Development >PHP Tutorial >How to Check if the Current Date and Time Have Passed a Specific Date and Time in PHP?
Checking Past Dates and Times Using PHP's Date Function
To determine if the current date and time surpasses a set reference point, PHP offers a comprehensive set of capabilities through its date() function. This article demonstrates how to leverage these capabilities for a common scenario.
Example Scenario:
You seek a PHP script that verifies if the present date and time have progressed beyond May 15, 2010, at 4:00 PM.
PHP Solution Using DateTime:
PHP's DateTime class empowers you with granular control over date and time manipulation. Consider the following code snippet:
<code class="php">if (new DateTime() > new DateTime("2010-05-15 16:00:00")) { # current time is greater than 2010-05-15 16:00:00 # in other words, 2010-05-15 16:00:00 has passed }</code>
In this code:
By utilizing this approach, you can effectively check if the current date and time have exceeded a predetermined point in the past.
The above is the detailed content of How to Check if the Current Date and Time Have Passed a Specific Date and Time in PHP?. For more information, please follow other related articles on the PHP Chinese website!