Date Time Code

  Home arrow Date Time Code arrow Current Age Script, up to the last day
DATE TIME CODE

Current Age Script, up to the last day
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2005-06-08

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    script that calculates the current age up to the last day.. grammar correct.

    By : voldomazta

    <?

    function curage($gm,$gd,$gy){

    /**
    * Current Age Script
    * Coded by Ramon Alivio Jr. (2005-06-12)
    * Iloilo City, Philippines
    * http://www.thermokarst.co.nr
    *
    * Usage: -- echo curage(m,d,y); --
    * Where 'm' is birth month, 'd' is birth day
    * and 'y' is birth year
    **/

    $r = '';

    /**
    * days of each month
    **/

    for($x=1 ; $x<=12 ; $x++){

    $dim[$x] = date('t',mktime(0,0,0,$x,1,date('Y')));

    }


    /**
    * vars for current date
    **/

    $cm = date('n');
    $cd = date('j');
    $cy = date('Y');


    /**
    * calculate differences
    **/

    $m = $cm - $gm;
    $d = $cd - $gd;
    $y = $cy - $gy;


    /**
    * if the given day is ahead of the current day
    **/

    if($d < 0) {

    $td = $cd + $dim[$cm];
    $tm = $cm - 1;
    $d = $td - $gd;
    $m = $tm - $gm;
    if(($tm - $gm) < 0) {

    $tm += 12;
    $ty = $cy - 1;
    $m = $tm - $gm;
    $y = $ty - $gy;

    }

    }


    /**
    * if the given month is ahead of the current month
    **/

    if($m < 0) {

    $tm = $cm + 12;
    $ty = $cy - 1;
    $m = $tm - $gm;
    $y = $ty - $gy;

    }


    /**
    * the processing area
    **/

    if($y < 0) {

    die("That date is in the future.");

    } else {

    switch($y) {

    case 0 : $r .= ''; break;
    case 1 : $r .= $y.($m == 0 && $d == 0 ? ' year old' : ' year'); break;
    default : $r .= $y.($m == 0 && $d == 0 ? ' years old' : ' years');

    }


    switch($m) {

    case 0: $r .= ''; break;
    case 1: $r .= ($y == 0 && $d == 0 ? $m.' month old' : ($y == 0 && $d != 0 ? $m.' month' : ($y != 0 && $d == 0 ? ' and '.$m.' month old' : ', '.$m.' month'))); break;
    default: $r .= ($y == 0 && $d == 0 ? $m.' months old' : ($y == 0 && $d != 0 ? $m.' months' : ($y != 0 && $d == 0 ? ' and '.$m.' months old' : ', '.$m.' months'))); break;

    }


    switch($d) {

    case 0: $r .= ($m == 0 && $y == 0 ? 'Today' : ''); break;
    case 1: $r .= ($m == 0 && $y == 0 ? $d.' day old' : ($y != 0 || $m != 0 ? ' and '.$d.' day old' : '')); break;
    default: $r .= ($m == 0 && $y == 0 ? $d.' days old' : ($y != 0 || $m != 0 ? ' and '.$d.' days old' : ''));

    }

    }

    return $r;

    }

    ?>
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Date Time Code Articles
    More By Codewalkers

    blog comments powered by Disqus

    DATE TIME CODE ARTICLES

    - DaysInSpan.php
    - MySQLdateSpan.php
    - DateSpan.php
    - FutureDateFormEntry.php
    - Generate Time Option List for Select stateme...
    - Current Age Script (v2)
    - class for some mysql imitated time functions
    - Current Age Script, up to the last day
    - filemtime_remote
    - Page Generation Time Figure-Outer
    - convGMT v2
    - Benchmarker
    - Simple PHP Calendar
    - Display message according to hour of day
    - Display Date Function

    Developer Shed Affiliates

     



    © 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap