Justtechjobs.com Find a programming school near you






Online Campus Both


php-general | 2005051

Re: [PHP] age function From: Petar Nedyalkov (bu <email protected>)
Date: 05/04/05

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

  • application/pgp-signature attachment: stored