• Register
    • Help

    striker  0 Items
    Currently Supporting
    • Home
    • News
    • Forum
      • Try XenForo Demo
      • New Posts
      • FAQ
      • Calendar
      • Community
        • Groups
        • Albums
        • Member List
      • Forum Actions
        • Mark Forums Read
      • Quick Links
        • Today's Posts
        • Who's Online
      • Sponsor
        • Sponsor a Feature
        • List of Donors
    • Wiki
    • Support
    • What's New?
    • Buy Now
    • Manual
    • 
    • Forum
    • VaultWiki How-Tos
    • VaultWiki Questions
    • Age from Date of Birth

    1. Welcome to VaultWiki.org, home of the wiki add-on for vBulletin and XenForo!

      VaultWiki allows your existing forum users to collaborate on creating and managing a site's content pages. VaultWiki is a fully-featured and fully-supported wiki solution for vBulletin and XenForo.

      The VaultWiki Team encourages you to join our community of forum administrators and check out VaultWiki for yourself.

    Results 1 to 4 of 4

    Thread: Age from Date of Birth

    • Thread Tools
      • Show Printable Version
    1. August 1, 2010 #1
      Moses
      • View Profile
      • View Forum Posts
      • View Blog Entries
      • Visit Homepage
      • View Articles
      Moses is offline
      Junior Member
      Join Date
      November 19, 2009
      Posts
      46
      Rep Power
      203

      Age from Date of Birth

      Hello,

      Is it possible to enter a date of birth and have the wiki calculate an age from this?

      Something like [AGE]28/7/2005[/AGE] could render as "5 years, 4 days old"
      Reply With Quote Reply With Quote

    2. August 1, 2010 #2
      pegasus
      • View Profile
      • View Forum Posts
      • View Blog Entries
      • Visit Homepage
      • View Articles
      pegasus is offline
      VaultWiki Team
      Join Date
      March 28, 2004
      Location
      New York, NY
      Posts
      2,959
      Blog Entries
      18
      Rep Power
      687
      There is no such mechanism. If there is a BB-Code mod that does, it should still work in the wiki.
      - lead developer for VaultWiki
      Reply With Quote Reply With Quote

    3. October 26, 2010 #3
      Moses
      • View Profile
      • View Forum Posts
      • View Blog Entries
      • Visit Homepage
      • View Articles
      Moses is offline
      Junior Member
      Join Date
      November 19, 2009
      Posts
      46
      Rep Power
      203
      Worked it out myself as a BBCode replacement!

      Title: Age
      BB Code Tag Name: Age
      Replacement
      Code:
      <script type="text/javascript">
          var now = new Date();
          var today = new Date(now.getYear(),now.getMonth(),now.getDate());
      
          var yearNow = now.getYear();
          var monthNow = now.getMonth();
          var dateNow = now.getDate();
      
      	var datestring = {param} + '';
              var dob = new Date(datestring.substring(0,4),
                                  datestring.substring(4,6)-1,
                                  datestring.substring(6,8));
          var yearDob = dob.getYear();
          yearAge = yearNow - yearDob;
      
          var monthDob = dob.getMonth();
      
          if (monthNow >= monthDob)
              var monthAge = monthNow - monthDob;
          else {
              yearAge--;
              var monthAge = 12 + monthNow -monthDob;
          };
      
          if (monthAge > 1) 
      	var monthDisplay = ' Months Old';
          else {
      	var monthDisplay = ' Month Old'
          };
      
      document.write (yearAge + ' Years, ' + monthAge + monthDisplay);
      </script>
      Example: [age]19760925[/age]
      Description: The date of birth in the format YYYYMMDD
      Use {option}: No

      Icon: age.gif


      Edit: looks like there is a minor bug - after you first submit a post with this code if messes up the AJAX load, you need to refresh the page
      Last edited by Moses; October 26, 2010 at 10:04 PM.
      Reply With Quote Reply With Quote

    4. October 26, 2010 #4
      pegasus
      • View Profile
      • View Forum Posts
      • View Blog Entries
      • Visit Homepage
      • View Articles
      pegasus is offline
      VaultWiki Team
      Join Date
      March 28, 2004
      Location
      New York, NY
      Posts
      2,959
      Blog Entries
      18
      Rep Power
      687
      document.write will erase the whole page if it is run on an AJAX load. Instead you should create a function to do this on the server-side, or use Javascript like this:
      Code:
      &lt;script type="text/javascript"&gt;
      &lt;!--
      if (typeof('birthday_bbcode') == "undefined")
      {
          var birthday_bbcode = true;
      
          YAHOO.util.Event.onDOMReady(function() {
              var datestring, dob, yearDob, monthDob, yearAge, monthAge, monthDisplay;
              var now = new Date();
              var today = new Date(now.getYear(),now.getMonth(),now.getDate());
      
              var yearNow = now.getYear();
              var monthNow = now.getMonth();
              var dateNow = now.getDate();
      
              var birthdays = YAHOO.util.Dom.getElementsByClassName("birthday", "span");
              for (var i = 0; i < birthdays.length; i++)
              {
                   datestring = birthdays[i].innerHTML;
                   dob = new Date(
                       datestring.substring(0,4),
                       datestring.substring(4,6)-1,
                       datestring.substring(6,8)
                   );
      
                   yearDob = dob.getYear();
                   yearAge = yearNow - yearDob;
      
                   monthDob = dob.getMonth();
      
                  if (monthNow >= monthDob)
                      monthAge = monthNow - monthDob;
                  else {
                      yearAge--;
                      monthAge = 12 + monthNow -monthDob;
                  }
      
                  if (monthAge > 1) 
      	        monthDisplay = ' Months Old';
                  else {
      	        monthDisplay = ' Month Old'
                  }
      
                  birthdays[i].innerHTML = yearAge + ' Years, ' + monthAge + monthDisplay;
              }
          });
      }
      //--&gt;
      &lt;/script&gt;
      &lt;span class="birthday">{param}&lt;/span>
      Note that while this will not erase the page if submitted via AJAX, the span won't show the relative timestamp after AJAX. If you need to satisfy all this, you'll need to parse and output the timestamp in PHP by using a callback function for your BB-Code.
      - lead developer for VaultWiki
      Reply With Quote Reply With Quote

    Tags for this Thread

    age, bbcode, birth, code, config, could, date, does, from, have, hello, here, like, mod, old, possible, replacement, ring, should, ted, that, the, there, this, wiki, work

    View Tag Cloud

    Bookmarks

    Bookmarks
    • Submit to Digg Digg
    • Submit to del.icio.us del.icio.us
    • Submit to StumbleUpon StumbleUpon
    • Submit to Google Google

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •  
    • BB code is On
    • Smilies are On
    • [IMG] code is Off
    • [VIDEO] code is
    • HTML code is Off

    Forum Rules

    • Contact Us
    • License Agreement
    • Privacy
    • Terms
    • Top
    All times are GMT -4. The time now is 5:51 AM.
    This site uses cookies to help personalize content, to tailor your experience, and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Learn more… Accept Remind me later
  • striker
    Powered by vBulletin® Version 4.2.5 Beta 2
    Copyright © 2025 vBulletin Solutions Inc. All rights reserved.
    Search Engine Optimisation provided by DragonByte SEO (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
    Copyright © 2008 - 2024 VaultWiki Team, Cracked Egg Studios, LLC.