Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Working with 'OLD' dates

Codes here !

Moderators: macek, egami, gesf

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
shai1
New php-forum User
New php-forum User
 
Posts: 4
Joined: Mon Apr 07, 2003 6:09 pm

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;
User avatar
bezmond
Moderator
Moderator
 
Posts: 312
Joined: Sat Apr 05, 2003 4:33 am
Location: Mansfield, UK

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
shai1
New php-forum User
New php-forum User
 
Posts: 4
Joined: Mon Apr 07, 2003 6:09 pm


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 3 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.