WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Simple function to return the number of days in a time span between 2 given dates.
Categories : PHP, Date Time, MySQL, Databases Click here to Update Your Picture
Dave Silvia
Date : Oct 13th 2006
Grade : 2 of 5 (graded 2 times)
Viewed : 3772
File : 4517.php
Images : No Images for this code example.
Search : More code by Dave Silvia
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

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.

DateSpan.php can be found at : http://www.weberdev.com/get_example-4515.html
MySQLdateSpan.php can be found at : http://www.weberdev.com/get_example-4516.html


<?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;
}
?>



Finding the day of the week for a specific date.
Categories : PHP, Databases, MySQL, Date Time
mysql date/time converters
Categories : PHP, MySQL, Databases, Date Time
Data Retrieve from Mysql using AJAX with PHP
Categories : PHP, AJAX, Date Time, Databases, MySQL
Phorum, MySQL, Language, UK date format, MySQL UK Date format
Categories : PHP, Date Time, Strings, MySQL, Databases
List people whose birthdays fall on the current Day and Month
Categories : Databases, Date Time, MySQL, PHP
This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server.
Categories : Databases, MySQL, Complete Programs, PHP, Databases
Checks Date-Input from HTML-Forms and converts to YYYY-MM-DD Format for MySQL Date-Fields
Categories : MySQL, Date Time, PHP, Databases
Simple conversion functions to change MySQL dates to arrays, arrays to MySQL dates.
Categories : PHP, Arrays, Date Time, Databases, MySQL
Count how many weeks in the month have a specified day, such as Mon, Tue, etc. Var avail - number of days - first day name of the month, occurrences of Sun, occurrences of Mon, etc. Allows you to calculate number of working hours exclude Holidays.
Categories : Calendar, Date Time, PHP, Databases, MySQL
How to Insert a Date Format Into MySQL from PHP
Categories : PHP, Databases, MySQL, Date Time, Beginner Guides
bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager
Categories : MySQL, PHP, MySQL, Complete Programs, Databases
In Mysql, the 'datetime' data type is used to store date that looks like '2007-10-16 16:26:30'. we are going to design a function called mysqldate() that takes a mysql date and output format as input and outputs a well formated date.
Categories : PHP, Date Time, Databases, MySQL
formating MySQL Timestamp to get a propper Output. related : Timestamp, ereg_replace, mysql, substr
Categories : MySQL, PHP, Date Time, Databases
Accepts a database & hostname from a user and then HTTP username and password. Uses this to connect to a MySQL database. Produces a form based on the tables it finds there to allow the user to do SELECTs, INSERTs, and DELETEs.
Categories : Databases, PHP, MySQL, Complete Programs
phpAds, a complete banner and ad management system with detailled tracking and stats.
Categories : MySQL, Complete Programs, Ecommerce, PHP, Databases