Re: age function
| From: | Petar Nedyalkov | Date: | Wed, 04 May 2005 12:03:35 +0000 |
| Subject: | Re: age function | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-214410@lists.php.net to get a copy of this message | ||
On Tuesday 03 May 2005 22:41, Ryan A wrote:
> Hey,
> Anybody have an age function where i can pass a date object and get back an
> int?
>
> eg:
> $years_old=get_years("1979-12-07");
Use time and mktime.
$birthday = ""1979-12-07";
$birdthday_time = mktime(0, 0, 0, substr($birthday, 5, 2), substr($birthday,
8, 2), substr($birthday, 0, 4));
$now_time = time();
$years = (int) (($now_time - $birthday_time) / 60*60*24*365.25);
I haven't tested the code - it's just an idea.
>
> Thanks,
> Ryan
>
>
>
> --
> No virus found in this outgoing message.
> Checked by AVG Anti-Virus.
> Version: 7.0.308 / Virus Database: 266.11.2 - Release Date: 5/2/2005
--
Cyberly yours,
Petar Nedyalkov
Devoted Orbitel Fan :-)
PGP ID: 7AE45436
PGP Public Key: http://bu.orbitel.bg/pgp/bu.asc
PGP Fingerprint: 7923 8D52 B145 02E8 6F63 8BDA 2D3F 7C0B 7AE4 5436
Attachment: [application/pgp-signature]
Attachment: [application/pgp-signature]