Date Time Code
  Home arrow Date Time Code arrow Current Age Script (v2)
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DATE TIME CODE

Current Age Script (v2)
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    2005-07-02

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    a sequel to my Current Age Script, now it supports up to the last minute. The new catch though, is it only supports times after the unix epoch, because the main function im using here is strtotime(). But there is a workaround to this though, you can avoid using strtotime by specifying the month, day, year, hour and minute in the variables.

    This could well be used in forums, for tracking how long the user has been away, or how old the post is, and stuff like that. Hope you enjoy.

    P.S.

    The class.grammar.php is just a grammar library I wrote which is responsible for concatenating the letters 's' to the words 'month', 'day', etc.. if the number is greater than one. It should be available on the archive.

    By : voldomazta

    <?

    // echo ts_date('June 23, 1988 06:55AM');
    // my birthday :)

    function ts_date($str_date,$str_append = 'old'){

    require('class.grammar.php');
    $g = new Grammar;

    $st = strtotime($str_date);

    /* Date Variables */
    $dv = array('mi'=>'i', 'h'=>'H', 'm'=>'n', 'd'=>'j', 'y'=>'Y');

    /* Days in Month */
    for($x=1 ; $x<=12 ; $x++) $dim[$x] = date('t',mktime(0,0,0,$x,1,date('Y')));

    /* Given Variables */
    foreach(array_keys($dv) as $gvt) {
    $tgvt = 'g'.$gvt;
    $$tgvt = date($dv[$gvt],$st);
    }

    /* Server Variables */
    foreach(array_keys($dv) as $svt) {
    $tsvt = 'c'.$svt;
    $$tsvt = date($dv[$svt]);
    }

    /* Differences */
    $mi = $cmi - $gmi;
    $h = $ch - $gh;
    $d = $cd - $gd;
    $m = $cm - $gm;
    $y = $cy - $gy;

    if($mi < 0) {
    $mi = ($cmi + 60) - $gmi;
    $h = ($ch - 1) - $gh;
    }

    if($h < 0) {
    $h = ($ch + 24) - $gh;
    $d = ($cd - 1) - $gd;
    }

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

    if($m < 0) {
    $m = ($cm + 12) - $gm;
    $y = ($cy - 1) - $gy;
    }

    if($y < 0) {
    die('Invalid Date');
    }


    /* Grammar Operations */

    if($y > 0) {
    $r .= $y.' '.$g->plural('year',$y);
    }

    if($m > 0) {
    if($y > 0) {
    $r .= (is_zero($d, $h, $mi) ? ' and ' : ', ');
    }
    $r .= $m.' '.$g->plural('month',$m);
    }

    if($d > 0) {
    if(is_pos($y, $m)) {
    $r .= (is_zero($h, $mi) ? ' and ' : ', ');
    }

    $r .= $d.' '.$g->plural('day',$d);
    }

    if($h > 0) {
    if(is_pos($y, $m, $d)) {
    $r .= ($mi == 0 ? ' and ' : ', ');
    }
    $r .= $h.' '.$g->plural('hour',$h);
    }

    if($mi > 0) {
    if(is_pos($y, $m, $d, $h)) {
    $r .= ' and ';
    }
    $r .= $mi.' '.$g->plural('minute',$mi);
    }

    return $r.' '.$str_append;

    }

    function is_zero() {
    foreach(func_get_args() as $arg) {
    if((int)$arg != 0) return false;
    }
    return true;
    }

    function is_pos() {
    foreach(func_get_args() as $arg) {
    if((int)$arg > 0) $pos += 1;
    }
    return ($pos > 0 ? true : false);
    }

    ?>

    Click to Download File



    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

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! Driving Business Success with Rational Process Library

    Join this webcast, to learn how the Rational Process Library can help with compliance issues, drive process improvement, and assist in service-oriented architecture (SOA) or Agile development. We will take a peek into the Rational Process Library with content around software and systems engineering (including RUP), operations and systems management, program and portfolio management, and asset and SOA governance.
    FREE! Go There Now!


    NEW! Did you say mainframe? e-kit

    Learn how you can extend modern application lifecycle management to IBM System z through the IBM Rational Software Delivery Platform (SDP). The Did you say mainframe? e-kit includes podcasts, webcasts, tutorials, white and red papers, demos, and articles designed to help ease the challenges of modernizing your enterprise. This complimentary kit for mainframe developers is a practical, how-to guide for making the most of an existing development environment, including the skills and infrastructure already in place at an established enterprise.
    FREE! Go There Now!


    NEW! Don't wait! Try the Rational Application Developer (RAD) v7.5 open beta code today

    Download the Rational Application Developer (RAD) v7.5 open beta code and start developing applications for the JEE5 standard which features EJB3.0, JPA, JSF 1.2, JSP 2.1 and Servlet 2.5 standards. When you use this beta you will see how you can increase developer productivity for already existing applications with improved support for refactoring, as well as adding new features to existing applications. In addition, the beta provides tooling for JD Edwards, Oracle, SAP, Siebel and PeopleSoft to improve the developer productivity with these enterprise systems.
    FREE! Go There Now!


    NEW! Download DB2 9.5 for Linux, Unix, and Windows

    Download a free trial version of IBM DB2 9.5 for Linux, UNIX, and Windows. DB2 9 is the result of a five-year development project that transformed traditional (static) database technology into an interactive data server that merges the high performance and ease of use of DB2 with the self-describing benefits of XML.
    FREE! Go There Now!


    NEW! Download IBM Data Studio V1.1

    Visit IBM developerWorks to download the latest trial version of IBM Data Studio V1.1 at no cost. IBM Data Studio is a comprehensive data management solution that helps you effectively design, develop, deploy and manage your data, databases, and database applications throughout the data management life cycle utilizing a consistent and integrated user interface. Unlike other client-side data management solutions that focus on only one aspect of the application lifecycle or database administration, Data Studio complements the Rational Software Delivery platform, providing unparalleled flexibility for a heterogeneous data server environment across platforms.
    FREE! Go There Now!


    NEW! Evaluate IBM Lotus Sametime Standard V8.0

    Visit IBM developerWorks to download a free trial of the latest release of IBM Lotus Sametime Standard V8.0. Lotus Sametime Standard V8.0 is a platform for unified communications and collaboration that combines security features with an extensible, open solution including integrated Voice over IP, geographic location awareness, mobile clients, and a robust Business Partner community offering telephony and video integration.
    FREE! Go There Now!


    NEW! IBM Rational Systems Development e-Kit

    As systems increase in complexity, communication between systems and software teams becomes more and more difficult. Now, there’s a way to improve product quality and communication.<br />Read the “Model Driven Systems Development” white paper to see how. Also included in this kit are more educational white papers, customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems.<br />
    FREE! Go There Now!


    NEW! Project and Portfolio Management Executive Resource Kit

    Portfolio Management is about effectively managing portfolio value by aligning portfolio investments with business goals. This complimentary e-kit provides a collection of materials that can help you understand how IBM Rational enables and automates best practices for improved governance and clear visibility into portfolio and project performance across the entire IT project lifecycle.
    FREE! Go There Now!


    NEW! Rational Talks to You: Manage RUP-based CMMI initiatives

    Join this Rational Talks to You teleconference on December 4 at 1:00 pm ET to discuss how Rational Method Composer can help meet your compliance objectives. Get your questions answered!
    FREE! Go There Now!


    NEW! Test terminal-based applications with Rational Functional Tester

    Regression testing -- in which code is thoroughly tested to ensure that changes have not produced unexpected results -- is an important part of any development process. But many testing environments neglect the terminal-based applications that still form the backbone of many industries. In this tutorial, you'll learn how the Rational Functional Tester Extension for Terminal-Based Applications works with other Rational Functional Tester to help test terminal-based applications quickly and easily.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    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





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    Stay green...Green IT