Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23
  1. #16
    New Coder
    Join Date
    Aug 2014
    Posts
    12
    Thanks
    3
    Thanked 0 Times in 0 Posts
    [COvar today = new Date() ;
    var dobf = this.getField("dob") ;
    var agef = this.getField("age") ;
    var dob = new Date(util.scand("mm/dd/yyyy",dobf.value)) ;

    var ddiff = 0;
    var mdiff = 0;
    var ydiff = 0;

    if (today.getDate() - dob.getDate() < 0) {
    ddiff = today.getDate() ;
    ddiff += new Date(today.getFullYear(), today.getMonth(), 0).getDate() - dob.getDate() ;
    mdiff-- ;
    } else {
    ddiff = today.getDate() - dob.getDate() ;
    }
    if (today.getMonth() - dob.getMonth() < 0) {
    mdiff += (today.getMonth() + (12 - dob.getMonth())) ;
    ydiff-- ;
    } else {
    mdiff += (today.getMonth() - dob.getMonth()) ;
    }
    ydiff += today.getFullYear() - dob.getFullYear() ;

    agef.value = ydiff ;
    DE][/CODE]

  2. #17
    New Coder
    Join Date
    Aug 2014
    Posts
    12
    Thanks
    3
    Thanked 0 Times in 0 Posts
    PHP Code:
    [CODE]var today = new Date() ;
    var 
    dobf this.getField("dob") ;
    var 
    agef this.getField("age") ;
    var 
    dob = new Date(util.scand("mm/dd/yyyy",dobf.value)) ;

    var 
    ddiff 0;
    var 
    mdiff 0;
    var 
    ydiff 0;

    if (
    today.getDate() - dob.getDate() < 0) {
    ddiff today.getDate() ;
    ddiff += new Date(today.getFullYear(), today.getMonth(), 0).getDate() - dob.getDate() ;
    mdiff-- ;
    } else {
    ddiff today.getDate() - dob.getDate() ;
    }
    if (
    today.getMonth() - dob.getMonth() < 0) {
    mdiff += (today.getMonth() + (12 dob.getMonth())) ;
    ydiff-- ;
    } else {
    mdiff += (today.getMonth() - dob.getMonth()) ;
    }
    ydiff += today.getFullYear() - dob.getFullYear() ;

    agef.value ydiff ;
     [/
    CODE

  3. #18
    New Coder
    Join Date
    Aug 2014
    Posts
    12
    Thanks
    3
    Thanked 0 Times in 0 Posts
    var today = new Date() ;
    var dobf = this.getField("dob") ;
    var agef = this.getField("age") ;
    var dob = new Date(util.scand("mm/dd/yyyy",dobf.value)) ;

    var ddiff = 0;
    var mdiff = 0;
    var ydiff = 0;

    if (today.getDate() - dob.getDate() < 0) {
    ddiff = today.getDate() ;
    ddiff += new Date(today.getFullYear(), today.getMonth(), 0).getDate() - dob.getDate() ;
    mdiff-- ;
    } else {
    ddiff = today.getDate() - dob.getDate() ;
    }
    if (today.getMonth() - dob.getMonth() < 0) {
    mdiff += (today.getMonth() + (12 - dob.getMonth())) ;
    ydiff-- ;
    } else {
    mdiff += (today.getMonth() - dob.getMonth()) ;
    }
    ydiff += today.getFullYear() - dob.getFullYear() ;

    agef.value = ydiff ;

  4. #19
    New Coder
    Join Date
    Aug 2014
    Posts
    12
    Thanks
    3
    Thanked 0 Times in 0 Posts
    [code]var today = new Date() ;
    var dobf = this.getField("dob") ;
    var agef = this.getField("age") ;
    var dob = new Date(util.scand("mm/dd/yyyy",dobf.value)) ;

    var ddiff = 0;
    var mdiff = 0;
    var ydiff = 0;

    if (today.getDate() - dob.getDate() < 0) {
    ddiff = today.getDate() ;
    ddiff += new Date(today.getFullYear(), today.getMonth(), 0).getDate() - dob.getDate() ;
    mdiff-- ;
    } else {
    ddiff = today.getDate() - dob.getDate() ;
    }
    if (today.getMonth() - dob.getMonth() < 0) {
    mdiff += (today.getMonth() + (12 - dob.getMonth())) ;
    ydiff-- ;
    } else {
    mdiff += (today.getMonth() - dob.getMonth()) ;
    }
    ydiff += today.getFullYear() - dob.getFullYear() ;

    agef.value = ydiff ;
    [code]

  5. #20
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    946
    Thanks
    0
    Thanked 129 Times in 128 Posts
    This is your old code!?! Totally discard that. As i said: it is errornous and unnecessarily complicated
    I thought you where trying out my code, with a possible errornous implementation.

    The basics of my code:
    Get the difference in years simply by ( years of age = current year - birth year )
    Then it tests if the birthday is reached this year. if not: substract 1 from years of age.

    try this ( without your code included )
    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title></title>
    <meta charset="windows-1252">
    <script>
    function getAge() {
    agef=document.getElementById('age');
    birthDay=document.getElementById('dob').value;
    birthDate=parseInt(BirthDay.substr(3,2));
    birthMonth=parseInt(BirthDay.substr(0,2));
    birthYear=parseInt(BirthDay.substr(6,4));
    now=new Date();
    nowDate=now.getDate();
    nowMonth=now.getMonth();
    nowYear=now.getFullYear();
    nears=NowYear-birthYear;
    if (nowMonth<birthMonth || (nowMonth==birthMonth && nowDate<birthDate)){
    Years--;
    }
    agef.value=years;
    }
    </script>
    </head>
    <body>
    Date of birth<input id="dob"><br>
    Years of age<input id="age"><br>
    <input type="button" onclick="getAge()">
    </body>
    </html>
    Last edited by Lerura; 08-11-2014 at 06:43 AM.

  6. #21
    New Coder
    Join Date
    Aug 2014
    Posts
    12
    Thanks
    3
    Thanked 0 Times in 0 Posts
    I know you are trying hard, but this one os full of errors, remember its a Adobe /acrobat PDF calculation Script, this one was a nightmare

  7. #22
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    946
    Thanks
    0
    Thanked 129 Times in 128 Posts
    Okay! Now I get it.
    but you old code is not proper javascript.
    but a mixup of Javascript, a lot of errors , and something that looks like it is Java

    But I can try to modify an simplify your old code:
    Code:
    var today = new Date() ; 
    var dobf = this.getField("dob") ; 
    var agef = this.getField("age") ; 
    var dob = new Date(util.scand("mm/dd/yyyy",dobf.value)) ;
    
    var ydiff = 0; 
    
    ydiff = today.getFullYear() - dob.getFullYear() ;
    if (today.getMonth() < dob.getMonth()) {
    ydiff-- ;
    } else {
    if (today.getMonth() == dob.getMonth() && today.getDate() < dob.getDate()) {
    ydiff-- ;
    }
    }
    agef.value = ydiff ; 
    Last edited by Lerura; 08-11-2014 at 07:08 AM.

  8. Users who have thanked Lerura for this post:

    Gqman (08-11-2014)

  9. #23
    New Coder
    Join Date
    Aug 2014
    Posts
    12
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Finally ... WOOOWHEEEE Thank you that was driving me crazy .... THANK YOU


 
Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •