News:

SMF 2.1.6 has been released! Take it for a spin! Read more.

Main Menu

PHP: Finding if someone is under 13 years of age..

Started by Tristan Perry, February 05, 2005, 03:33:25 PM

Previous topic - Next topic

Tristan Perry

Hello,
I am working on a project, and the registration must comply with the COPPA law. I'm trying to work out if an age is under 13 from a date of birth.. I have the fields: year, month and day on the registration form. From this, how can I find out the age? I've tried a few things but none of them work..
I'd appreciate any help,
Thanks.

[Unknown]

Compile them together into a timestamp (using, for example, mktime()...), and then do time() - 13 * 365 * 24 * 3600 or so.

-[Unknown]

Tristan Perry

Quote from: [Unknown] on February 05, 2005, 05:18:06 PM
Compile them together into a timestamp (using, for example, mktime()...), and then do time() - 13 * 365 * 24 * 3600 or so.

-[Unknown]
Thanks, although I'm still not getting this. I can understand the kind of thing I have to do, although I can't seem to make this work.. What am I doing wrong?

<?php
$dob1
= 1990; // Year
$dob2 = 04; // Month
$dob3 = 14; // Day

$dob = mktime(0,0,0,$dob2,$dob3,$dob1);
$compare = time() - 13 * 365 * 24 * 3600;

// This is just to see if I'm doing the correct thing
echo $compare.'<br />'.$dob;
?>


Using the above I come up with something like:

697716062
640069200

(= 57646862)

[Unknown]

Righto.  The compare number represents 13 years ago.... and the other number represents their birthdate.

Because the second number ($dob) is lower than the first number (13 years ago) that means they're older than 13!

-[Unknown]

Tristan Perry

Quote from: [Unknown] on February 06, 2005, 05:10:33 AM
Righto.  The compare number represents 13 years ago.... and the other number represents their birthdate.

Because the second number ($dob) is lower than the first number (13 years ago) that means they're older than 13!

-[Unknown]
Ah right!  :) Thanks a lot, you've been a great help! I was thinking after doing the mktime() thing, I'd take the first number away from the second to find the age or something like that!

[Unknown]

Actually, that could work too.  You could do today's date minus 13 years... e.g. 20050206 - 130000.  That would be thirteen years ago.  Then, you could take their date, concatenate it together like that, and compare (YYYYMMDD.)

-[Unknown]

Tristan Perry

Quote from: [Unknown] on February 06, 2005, 05:25:17 AM
Actually, that could work too.  You could do today's date minus 13 years... e.g. 20050206 - 130000.  That would be thirteen years ago.  Then, you could take their date, concatenate it together like that, and compare (YYYYMMDD.)

-[Unknown]
Yeah that's what I tried firstly but I got confused! I think I'll stick to the first method  :)

SeaOfSin

Does anyone know if this was completed, I'm looking for something similar!!!!! All I have is this to work with :-
Quote from: Tau Online on February 06, 2005, 05:01:35 AM
Quote from: [Unknown] on February 05, 2005, 05:18:06 PM
Compile them together into a timestamp (using, for example, mktime()...), and then do time() - 13 * 365 * 24 * 3600 or so.

-[Unknown]
Thanks, although I'm still not getting this. I can understand the kind of thing I have to do, although I can't seem to make this work.. What am I doing wrong?

<?php
$dob1
= 1990; // Year
$dob2 = 04; // Month
$dob3 = 14; // Day

$dob = mktime(0,0,0,$dob2,$dob3,$dob1);
$compare = time() - 13 * 365 * 24 * 3600;

// This is just to see if I'm doing the correct thing
echo $compare.'<br />'.$dob;
?>


Using the above I come up with something like:

697716062
640069200

(= 57646862)


I'm not sure how to finish it!

Thanks

Sea Of Sin

bloc

You need to convert that to actual years. Try using
    echo date("Y",$compare);

Advertisement: