|
|
|
Code contains a fully functional illustrative example.
Useful for determining, say, if a date a user has entered falls during your vacation?;)
DateSpan.php
| <?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().
*/
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);
}
?> | |
Usage Example
|
A simple illustrator to show how the functions are used.
btw, ES|es stands for 'Epoch Seconds'
<?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 />");
}
}
?> | | |
|
| A Timing Class Categories : PHP, PHP Classes, Date Time | | | Finding the day of the week for a specific date.
Categories : PHP, Databases, MySQL, Date Time | | | A PHP Calendar function with CSS : add a cool calendar to any php page by just adding a calendar class based function. Categories : PHP, PHP Classes, Calendar, Date Time | | | A wrapper function to format dates coming from a databases with the
same syntax as PHP's date() function. Categories : Date Time, Databases, PHP | | | pcCalendar class - Allows for the creation of calendars in HTML pages. All output functions can be easily overridden, refer to article 1471 for an example.
Categories : PHP, Date Time, Calendar, PHP Classes | | | PHP Round Clock - Must have Gif support to use this. Categories : PHP, Date Time, Graphics | | | A simple and fast calendar combining PHP and tables. Use this as a base for applications in which a calendar is needed. Categories : Date Time, PHP, Complete Programs, Calendar | | | Open and Close your website in fixed times . Categories : PHP, PHP Classes, Cron, Date Time | | | mysql date/time converters Categories : PHP, MySQL, Databases, Date Time | | | Creates three SELECT form fields: Month, Day, and Year. You give it a string which will be used to make the name for the three fields, and a number of seconds to use as the default date. If you give it blank for this value, the current date is used. Categories : HTML and PHP, PHP, Date Time | | | If you want to create select buttons featuring current date this example will show you how... Categories : Date Time, HTML and PHP, PHP | | | Example of using the pcCalendar class, article 1468 on weberdev.com. Calendar example. Categories : PHP, Date Time, PHP Classes, Calendar | | | Monthly and Daily Upcoming Events calendar. Categories : Date Time, PostgreSQL, PHP, Calendar, Databases | | | calculus of the eastersunday Categories : BC math, PHP, Date Time, Databases | | | Functions used to define a schedule of holidays. Can define non-fixed holidays (eg. 3rd sunday of June). Categories : Calendar, Date Time, PHP | |
|
|
|