Working with 'OLD' dates

Codes here !

Moderators: macek, egami, gesf

shai1
New php-forum User
New php-forum User
Posts: 4
Joined: Mon Apr 07, 2003 6:09 pm

Working with 'OLD' dates

Postby shai1 » Mon Apr 07, 2003 6:54 pm

I have a MySQL DB which contains birthdates. I want to do things like calculate current age from it. I'm having problems because of the limitation of timestamps (1970).

I was thinking I would get the current date and compare it with the old date to get ones age. How can I do this if I'm limited to dates after 1970?

Any help would be much apprecieated!
Dave

User avatar
bezmond
Moderator
Moderator
Posts: 312
Joined: Sat Apr 05, 2003 4:33 am
Location: Mansfield, UK
Contact:

Postby bezmond » Mon Apr 07, 2003 10:41 pm

assuming you know how to retrieve the date from your database and assign it a variable (which I will call $year), you can use the following:

Code: Select all

$date = date(Y);
$age = $date - $year;
echo $age;

shai1
New php-forum User
New php-forum User
Posts: 4
Joined: Mon Apr 07, 2003 6:09 pm

Postby shai1 » Tue Apr 08, 2003 6:54 pm

I would agree that this would return an age, but it might not be the correct age depending on current date vs. birth date. If my birthday is at the end of year and and it is currently April then it will return an age 1 year older then I am.

Any other ideas?

Thanks,
Dave


Return to “mySQL & php coding”

Who is online

Users browsing this forum: Bing [Bot] and 2 guests