Date Time Code

  Home arrow Date Time Code arrow DateSpan.php
DATE TIME CODE

DateSpan.php
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 2
    2006-10-13

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    Simple function to check if a given date falls within a given time span.

    Code contains a fully functional illustrative example. Just change the commenting as instructed in the file to run the example. It's a matter of changing a single character (from '/' to '*').

    Useful for determining, say, if a date a user has entered falls during your vacation?;)

    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 check if a given date falls within a given time span.
    *
    * Arguments are arrays of the form array(dayNum,monthNum,yearNum) as recognized
    * by the standard php function mktime().
    *
    * Example:
    * A simple illustrator to show how the functions are used.
    *
    * btw, ES|es stands for 'Epoch Seconds'
    *
    replace first character, single line comment character slash ('/'),
    with multiline comment character star ('*')
    in the line below to use the test code
    //?>

    <?php
    include_once('DateSpan.php');
    $startDate=array(1,1,2006);
    $endDate=array(1,1,2007);
    $find[0]=array(1,8,2007);
    $find[1]=array(4,8,2006);
    $esTime1=dateAryEStime($startDate);
    $esTime2=dateAryEStime($endDate);
    $date1=date("M-d-Y",$esTime1);
    $date2=date("M-d-Y",$esTime2);
    for($i=0; $i < 2; $i++)
    {
    $date3=date("M-d-Y",dateAryEStime($find[$i]));
    if(dateBetween($startDate,$endDate,$find[$i]))
    {
    print("$date3 falls between $date1 and $date2 (inclusive)<br />");
    }
    else
    {
    print("$date3 falls outside $date1 and $date2 (inclusive)<br />");
    }
    }
    ?>

    <?php /*
    *
    */


    function dateBetween($start,$end,$theDate)
    {
    $startES=dateAryEStime($start);
    $endES=dateAryEStime($end);
    $findES=dateAryEStime($theDate);
    return ($startES <= $findES && $findES <= $endES);
    }

    function dateAryEStime($theDate)
    {
    return dateEStime($theDate[0],$theDate[1],$theDate[2]);
    }

    function dateEStime($theDay,$theMonth,$theYear)
    {
    return mktime(0,0,0,$theMonth,$theDay,$theYear);
    }
    ?>

    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