Date Time Code
  Home arrow Date Time Code arrow DaysInSpan.php
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

DaysInSpan.php
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 2
    2006-10-13

    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


    Simple function to return the number of days in a time span between 2 given dates.

    Arguments are long integers as returned by the standard php function mktime().
    Arguments can be generated using mktime(), dateEStime(), or
    dateAryEStime(mySQLdate2Ary()).

    Example:
    A simple illustrator to show how the function is used.

    Change comment characters on lines indicated to use text code.
    The test code can be used singly or multiply.

    By : dsilvia

    <?php
    /*
    * (c) 2006, D.E. Silvia, All rights reserved.
    * This code is available for use for non-commercial purposes.
    * Free to distribute as long as this copyright information remains intact.
    * No modification is authorized. Please, refer bugs/enhancements to
    * dsilvia@mchsi.com
    *
    */

    /*
    * Simple function to return the number of days in a time span between 2 given dates.
    *
    * Arguments are long integers as returned by the standard php function mktime().
    * Arguments can be generated using mktime(), dateEStime(), or
    * dateAryEStime(mySQLdate2Ary()).
    *
    * Example:
    * A simple illustrator to show how the function is used.
    *
    * Change comment characters on lines indicated to use text code.
    * The test code can be used singly or multiply.
    *
    * btw, ES|es stands for 'Epoch Seconds'
    *

    // Change line below from slash-slash to star-slash to use test code
    //
    $numDays00=daysInSpan(mktime(0,0,0,1,1,2000),mktime(0,0,0,4,1,2000));
    $numDays01=daysInSpan(mktime(0,0,0,1,1,2001),mktime(0,0,0,4,1,2001));

    print("Using mktime()<br />");
    print("The first quarter of 2000 has $numDays00 days (leap year)<br />");
    print("The first quarter of 2001 has $numDays01 days (not a leap year)<br /><br />");

    /*
    *
    // Change line below from slash-slash to star-slash to use test code
    //
    // using DateSpan.php
    include_once('DateSpan.php');
    $numDays00=daysInSpan(dateEStime(1,1,2000),dateEStime(1,4,2000));
    $numDays01=daysInSpan(dateEStime(1,1,2001),dateEStime(1,4,2001));

    print("Using dateEStime() from DateSpan.php<br />");
    print("The first quarter of 2000 has $numDays00 days (leap year)<br />");
    print("The first quarter of 2001 has $numDays01 days (not a leap year)<br /><br />");
    /*
    *
    */

    /*
    *
    // Change line below from slash-slash to star-slash to use test code
    //
    // using MySQLdateSpan.php
    include_once('MySQLdateSpan.php');
    $numDays00=daysInSpan(dateAryEStime(mySQLdate2Ary('2000-1-1')),dateAryEStime(mySQLdate2Ary('2000-4-1')));
    $numDays01=daysInSpan(dateAryEStime(mySQLdate2Ary('2001-1-1')),dateAryEStime(mySQLdate2Ary('2001-4-1')));

    print("Using mySQLdate2Ary() from MySQLdateSpan.php<br />");
    print("The first quarter of 2000 has $numDays00 days (leap year)<br />");
    print("The first quarter of 2001 has $numDays01 days (not a leap year)<br />");
    /*
    *
    */


    function daysInSpan($start,$end)
    {
    $dayTicks=ticksInDay();
    return ($end-$start)/$dayTicks;
    }

    function ticksInDay()
    {
    $today=getdate();
    $yesterday=mktime(0,0,0,$today[mon],$today[mday]-1,$today[year]);
    $today=mktime(0,0,0,$today[mon],$today[mday],$today[year]);
    return $today-$yesterday;
    }
    ?>
    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!


    Be the first to hear about i5/OS V6R1!

    Hold your calendar on January 30, 2008 for this free webcast on the new i5/OS. Rational's Enterprise Modernization products will be discussed at this webcast as they help to drive the application development environment for this new System i OS. <br />And learn how i5/OS will take you to the next step of efficient, resilient business processing. You will hear about the new i5/OS capabilities as it will be the most significant i5/OS release in years. If you cannot join the webcast on 1/30/08 you can still use this link to listen to the replay.<br />
    FREE! Go There Now!


    NEW! Build Web services with transport-level security using Rational Application Developer V7, Part 1: Build Web services and Web services clients

    Build secure Web services with transport-level security using IBM Rational Application Developer V7 and IBM WebSphere Application Server V6.1. Follow this three-part series for step-by-step instructions about how to develop Web services and clients, configure HTTP basic authentication, and configure HTTP over SSL (HTTPS). This first part of the series walks you through building a Web service for a simple calculator application. You generate and test two different types of Web services clients: a Java Platform, Enterprise Edition (Java EE) client and a stand-alone Java client. You also handle user-defined exceptions in Web services.
    FREE! Go There Now!


    NEW! Evaluate IBM Rational Software Analyzer V7.0

    Download a free trial version of IBM Rational Software Analyzer Developer Edition V7.0 to identify bug defects earlier in the software development cycle. Rational Software Analyzer is an extensible software development solution that reduces the expense of bug-fixes by enabling static analysis code reviews and bug identification very early in the development cycle.
    FREE! Go There Now!


    NEW! Rational Talks to You: Grady Booch on Architecture

    Join this Rational Talks to You teleconference on November 29 at 1:00 pm ET to participate in an interactive discusssion with Grady Booch around architecture and reuse. Get your questions answered!
    FREE! Go There Now!


    NEW! Rational Talks to You: Scott Ambler on being agile in a global development environment

    Join this Rational Talks to You teleconference on December 6 at 1:00 pm ET to participate in an agile application development discussion and get your questions answered on using IBM Rational Method Composer in a distributed environment.Get your questions answered!
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Manual Tester V7.0.1

    Try the latest version of IBM Rational Manual Tester V7.0.1 by downloading a free trial from IBM developerWorks. This manual test authoring and execution tool promotes test step reuse to reduce the impact of software change on testers and business analysts and addresses the needs of teams performing at least a portion of their testing manually.
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Method Composer V7.2

    Get a free trial download of the latest version of IBM Rational Method Composer V7.2 which helps you deliver customized yet consistent process guidance to your project teams and IT organization, and includes the latest version of IBM Rational Unified Process (RUP), which has provided process guidance to teams since 1996.
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Performance Tester V7.0.1

    Get a free trial download of the latest version of IBM Rational Performance Tester V7.0.1, a load and performance testing solution for teams concerned about the scalability of their Web-based applications. Combining multiple ease-of-use features with granular detail, Rational Performance Tester simplifies the test-creation, load-generation and data-collection processes that help teams ensure the ability of their applications to accommodate required user loads.
    FREE! Go There Now!


    NEW! Try the IBM SOA Sandbox for People

    Visit IBM developerWorks to try the IBM SOA Sandbox for people. The SOA Sandbox for people provides a trial environment with the necessary tooling and components required to enable consistent human and process interaction and collaboration, showing how you can improve user experience and business productivity.
    FREE! Go There Now!


    NEW! Whitepaper: Delivering SOA solutions: service lifecycle management

    The unprecedented scope of a service-oriented architecture (SOA) initiative brings to the forefront a number of management and governance issues that were sidestepped in the past. The key to a successful SOA implementation is managing and governing activities throughout the entire SOA delivery lifecycle by ensuring that services conform to the needs of all of the business’s stakeholders. Learn how service lifecycle management allows the business to ensure that the process by which services are defined, created, tested, deployed, optimized and retired is manageable, repeatable and auditable.
    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 2 Hosted by Hostway
    Stay green...Green IT