|
Author |
Message |
thor
WebHelper
Joined: 10 Mar 2003
Posts: 71
|
Posted:
Mon Apr 11, 2005 3:41 pm (19 years ago) |
|
Hey
I no nothing about server side coding and i was wondering if anybody knows of a small script that will work out somebodys age from their date of birth possibly a php script? |
|
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Mon Apr 11, 2005 4:39 pm (19 years ago) |
|
Hi,
Hope this will help:
http://www.php.net/date wrote: |
A little function who calculate people age with their date of birth.
The format of date used is the one used in mysql table. (For example: 2004-10-23)
Code: | <?php
function CalcAge($date_of_birth) { // YYYY-MM-DD
$cur_year=date("Y");
$cur_month=date("m");
$cur_day=date("d");
$dob_year=substr($date_of_birth, 0, 4);
$dob_month=substr($date_of_birth, 5, 2);
$dob_day=substr($date_of_birth, 8, 2);
if($cur_month>$dob_month || ($dob_month==$cur_month && $cur_day>=$dob_day) )
return $cur_year-$dob_year;
else
return $cur_year-$dob_year-1;
}
?> |
|
|
________________________________
|
|
|
|
thor
WebHelper
Joined: 10 Mar 2003
Posts: 71
|
Posted:
Mon Apr 11, 2005 5:31 pm (19 years ago) |
|
hmm it doesn't appear to work i get a parse error for the second line of it |
|
|
|
|
Darren
Team Member
Joined: 05 Feb 2002
Posts: 549
Location: London
|
Posted:
Sat Apr 16, 2005 6:51 pm (19 years ago) |
|
I just tried and also got the parse error. However there is nothing wrong with the code it was just that copying and pasting from the forum caused there to be a lot of invisible characters, basically all of the indentation.
If your text editor can display invisibles turn it on and it should show them so you can delete them. Or just delete any spaces before and after each line.
Or try this version of the code which I have cleaned up and seems to be OK:
Code: | <?php
function CalcAge($date_of_birth) { // YYYY-MM-DD
$cur_year=date("Y");
$cur_month=date("m");
$cur_day=date("d");
$dob_year=substr($date_of_birth, 0, 4);
$dob_month=substr($date_of_birth, 5, 2);
$dob_day=substr($date_of_birth, 8, 2);
if($cur_month>$dob_month || ($dob_month==$cur_month && $cur_day>=$dob_day) )
return $cur_year-$dob_year;
else
return $cur_year-$dob_year-1;
}
echo CalcAge("1999-05-05");
?> |
|
|
|
|
|
thor
WebHelper
Joined: 10 Mar 2003
Posts: 71
|
Posted:
Mon Apr 18, 2005 2:55 pm (19 years ago) |
|
thanks that worked great |
|
|
|
|
zunixaani
Junior WebHelper
Joined: 25 Feb 2015
Posts: 1
|
Posted:
Wed Feb 25, 2015 6:26 am (9 years, 2 months ago) |
|
ok i have figured out the problem with this and the problem was how i done the datapath.cs
instead of doing like this
Code: |
________________________________ We offer guaranteed success for Testking hesi practice test exam with help ccna security of latest certification and practice questions and the exams of sterling ccie security www.mcdaniel.edu |
|
|
|
|
|
You cannot post new topics in this forum. You cannot reply to topics in this forum. You cannot edit your posts in this forum. You cannot delete your posts in this forum. You cannot vote in polls in this forum.
|
Page generation time: 0.14934 seconds :: 18 queries executed :: All Times are GMT
Powered by phpBB 2.0
© 2001, 2002 phpBB Group :: Based on an FI Theme
| |