How to check time between two date variables in php?
P粉831310404
2023-08-16 13:21:21
<p>I have 3 variables, which are 3 numbers (day, year, month).
Together they become a date type variable.
Additionally, I have a date variable that represents the current date. </p>
<p>How can I check if the first date is 13 years or more before the current date?
Here is my code: </p>
<pre class="brush:php;toolbar:false;">$usersday = (int)$_POST['day'];
$usersyear = (int)$_POST['year'];
$usersmonth = (int)$_POST['month'];
$takedate = date_create("$usersyear-$usersmonth-$usersday");
$date = date_format($takedate, 'd-m-Y');
$currentDate = date('Y-m-d');</pre>
<p><br /></p>
The
date_*()
functions anddate()
are part of two different date library APIs, confusingly. The object-oriented version of thedate_*()
functions clarifies this to some extent and is also a more powerful library. For example:Output:
Reference:https://www.php.net/manual/en/book.datetime.php