L
L
lexstile2022-03-27 23:29:55
PHP
lexstile, 2022-03-27 23:29:55

How to check age in php?

For example, a user fills out a form in the format dd.mm.yyyy (04/30/1993), we need to check if he is 18 years old.
Are there effective methods?

PS I don't really want to get the current day, month, year and compare it with the day, month and year from the user.
Perhaps there are easier solutions?

Also, I tried to compare in UNIX, but there are difficulties with the number of days in a year, which must be taken into account in the calculations.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
iBird Rose, 2022-03-27
@lexstile

<?php
$birthDate = '20.02.2010';
if (time() < strtotime('+18 years', strtotime($birthDate))) {
    echo 'меньше 18';
} else {
    echo 'больше 18';
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question