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  
Forums Sitemap 
Dedicated Servers  
Download TestComplete 
IBM® developerWorks
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: 5 stars5 stars5 stars5 stars5 stars / 1
    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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    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!


    NEW! IBM – Taking Web 2.0 to Work

    David Barnes, Lead Evangelist for IBM Emerging Internet Technologies will discuss aspects of Web 2.0 that bring value to corporations, academia, and government. He'll also discuss IBM's vision around Web 2.0, including the importance of remixability and consumability. The discussion will culminate with examples of various IBM Software Group solutions you can use to get ahead of the Web 2.0 adoption curve.
    FREE! Go There Now!


    NEW! Achieving True Agility -- How process can change the behavior of your tools

    Achieving true agility is a never-ending effort. We will showcase how you can become agile incrementally, a few practices at the time.Which practices should any agile team strive to adopt? What additional practices should you consider based on your needs to scale? Adopting practices are however made much easier with the right tool support. What about if your tools adapt to your practices? We will take a look at how the Jazz technology can be leveraged to make your process change the behavior of your tools.
    FREE! Go There Now!


    NEW! Application development for the OLPC laptop

    The XO laptop (of the One-Laptop-Per-Child initiative) is an inexpensive laptop project intended to help educate children around the world. The XO laptop includes many innovations, such as a novel, inexpensive, and durable hardware design and the use of GNU/Linux as the underlying operating system. The XO also includes an application environment written in Python with a human interface called Sugar, accessible to everyone (including kids). Explore the Sugar APIs and learn how to develop and debug a graphical activity in Sugar using Python.
    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! Download IBM Rational Developer for System z

    Download a free trial version of IBM Rational Developer for System z, software that can help you deliver core development capabilities; the power of Java Platform, Enterprise Edition (Java EE); and rapid application development support to diverse enterprise application development teams. With comprehensive development tools to help create, deploy and maintain traditional enterprise and composite applications, Rational Developer for System z enables developers with different technical backgrounds to easily participate in important technology projects.
    FREE! Go There Now!


    NEW! Kick-start your Java apps

    To create, test, and deploy a Web-based application or Web service rapidly, you need a proven relational database, a standards-compliant Web application server, and a flexible IDE. Ideally, all these software packages are production-tested, simple to obtain, easy to use, and well integrated with one another. This tutorial shows you how to use IBM-backed open source and free software to kick-start your Java Web-based application development. You'll learn exactly where to download such components, install them, and get them working for you today.
    FREE! Go There Now!


    NEW! Rational Modeling Extension for Microsoft.Net

    Rational Modeling Extension for Microsoft .NET enhances usability for code generation supporting a more intelligent refactoring. The latest enhancements enable organizations with Java and .NET systems and software development maintain architectural integrity across heterogeneous platforms.
    FREE! Go There Now!


    NEW! Successful Change and Release Management for .NET

    Join this webcast to discover the key requirements for successful change and release management. Learn how to extend your .NET environment to improve productivity and collaboration, and address core problems afflicting team development. In this webcast, we’ll review typical challenges faced by customers and how to resolve them with the IBM Rational Change and Release Management solution, including Rational ClearCase, Rational ClearQuest and Rational Build Forge. Replay is available for 9 months.
    FREE! Go There Now!


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

    Get a free trial download of the latest version of IBM Rational Functional Tester V7.0.1. Rational Functional Tester is an automated functional and regression testing solution for QA teams concerned with the quality of their Java, Microsoft Visual Studio .NET, and Web-based applications.
    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!



    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-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway