Simple conversion functions to change MySQL dates to arrays, arrays to MySQL dates.
mySQLdateBetween() determines if a given date falls within a given time span.
Arguments are either arrays (as used by DateSpan.php) or MySQL date strings.
MySQLdateSpan.php : The functions code
testMySQLdateSpan.php : A test script
test.sql : An sql script for instantiating the test MySQL database.
DateSpan.php can be found at : http://www.weberdev.com/get_example-4515.html
MySQLdateSpan.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 conversion functions to change MySQL dates to arrays,
* arrays to MySQL dates.
*
* mySQLdateBetween() determines if a given date falls within a
* given time span. Arguments are either arrays (as used by
* DateSpan.php) or MySQL date strings.
*
* Acts as MySQL layer to DateSpan.php
*
*/
if(mySQLdateBetween($start,$end,$anniv))
{
print($name."'s $which year anniversary is on ".ary2mySQLdate($anniv)." in the period between $start and $end<br />");
}
else
{
print($name."'s anniversary is not in the period between $start and $end<br />");
}
}
$request=mysql_query('select * from holidays');
print("<br />During the period between $start and $end, the Kansas City Board of Trade observes the following holidays<br/>");
while($holidayRow=mysql_fetch_row($request))
{
if(mySQLdateBetween($start,$end,$holidayRow[1]))
{
print($holidayRow[0]." is observed on ".$holidayRow[1]."<br />");
}
}
?>
test.sql
-- phpMyAdmin SQL Dump
-- version 2.8.2.4
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Oct 12, 2006 at 01:49 PM
-- Server version: 5.0.26
-- PHP Version: 5.1.6
--
-- Database: `test`
--
--
-- Table structure for table `anniversaries`
--
DROP TABLE IF EXISTS `anniversaries`;
CREATE TABLE IF NOT EXISTS `anniversaries` (
`name` varchar(128) NOT NULL,
`anniversary` date NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=ascii;
DROP TABLE IF EXISTS `holidays`;
CREATE TABLE IF NOT EXISTS `holidays` (
`name` varchar(64) NOT NULL,
`date` date NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=ascii;