4WebHelp
 FAQ  •  Search  •  User Groups  •  Forum Admins  •  Smilies List  •  Statistics  •  Rules   •  Login   •  Register
Toggle Navigation Menu

 Date, Age
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic
Author Message
thor
WebHelper
WebHelper


Joined: 10 Mar 2003
Posts: 71

PostPosted: Mon Apr 11, 2005 3:41 pm (19 years ago) Reply with QuoteBack to Top

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?
OfflineView User's ProfileFind all posts by thorSend Personal Message
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Mon Apr 11, 2005 4:39 pm (19 years ago) Reply with QuoteBack to Top

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;
   }   
?>

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
thor
WebHelper
WebHelper


Joined: 10 Mar 2003
Posts: 71

PostPosted: Mon Apr 11, 2005 5:31 pm (19 years ago) Reply with QuoteBack to Top

hmm it doesn't appear to work i get a parse error for the second line of it
OfflineView User's ProfileFind all posts by thorSend Personal Message
Darren
Team Member



Joined: 05 Feb 2002
Posts: 549
Location: London

PostPosted: Sat Apr 16, 2005 6:51 pm (19 years ago) Reply with QuoteBack to Top

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");
?>
OfflineView User's ProfileFind all posts by DarrenSend Personal MessageVisit Poster's Website
thor
WebHelper
WebHelper


Joined: 10 Mar 2003
Posts: 71

PostPosted: Mon Apr 18, 2005 2:55 pm (19 years ago) Reply with QuoteBack to Top

thanks that worked great Smile
OfflineView User's ProfileFind all posts by thorSend Personal Message
zunixaani
Junior WebHelper
Junior WebHelper


Joined: 25 Feb 2015
Posts: 1

PostPosted: Wed Feb 25, 2015 6:26 am (9 years, 1 month ago) Reply with QuoteBack to Top

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
OfflineView User's ProfileFind all posts by zunixaaniSend Personal Message
Display posts from previous:      
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic


 Jump to:   




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.211383 seconds :: 18 queries executed :: All Times are GMT
Powered by phpBB 2.0 © 2001, 2002 phpBB Group :: Based on an FI Theme