Date_Math_ClassA.php
This class has 67 date related functions. Dates can be outside the Linux date() range
of 1970-
Date range for this class is from the year 0032 A.D. to 9999 A.D.
USE:
require_once <path / Date_Math_ClassA.php>;
$dt = new date_math_class;
Documentation and examples are found in files
Date_Math_Class_TestA.php and
Date_Math_ClassA.php.pseudo.
Copyright (C) 2014 Software Installation Services, Inc.
Author: Bob Wedwick, Phoenix, AZ 602-
This program is free software: you can redistribute it or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License or any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
See http://www.gnu.org/licenses/licenses.en.html for a copy of the GNU General Public License.
This class operates by default on dates in string y-
Input dates as function parameters may be formatted as strings: y-
where 'y' is 4 digits (leading zeros for years before 1000), 'm' and 'd' may be 1 or 2 digits.
Example: AddDays(2, '2013-
is formatted as y/m/d.
Also supported is ymd format as a string or integer for input which must be
exactly 8 digits: 4-
Output date formats supported include those above as well as d-
Note the 'd-
Null or blank output date formats revert to the default format as do any other formats that are
not recognized. Thus null, blank, or unrecognized formats do not generate errors.
Formatting strings are not case sensitive.
Input and output formats do not have to be the same. Thus functions can be
used to convert date formats from one to another.
For functions expecting an integer value as an input parameter, it may be
either an integer or string with or without + or -
When the public variable $useTime = false (the default),
time blocks are not considered for calculations and are removed from the output.
When the public variable $useTime = true,
The input date string may have an optional time component which is preserved and returned.
Time blocks are used in many date comparisons where time may make a difference.
Any dates submitted without a valid time block are set to 00:00 (midnight).
Null and blank time blocks are set to the current Linux local time.
Date comparisons using time blocks operate on 24 hours (86400 seconds) to make one day.
Thus 2012-
likewise 2012-
When time blocks are not used, these entries result in different days.
Public variables for months, days of the week and 1st day of the weekmake it easy to change languages.
You can change the abbreviations for month and day of the week in public variables.
When the public variable $exceptions = true, an error throws an exception instead of returning
to the calling script with 'false' result.
Otherwise functions return a boolean false (result === false) whenever invalid input is passed
and should be explicitly tested by using ===.
Some functions may return zero which is different from the boolean false.
Null and blank dates are valid for input in selected functions where replacing them with the
current date and time makes sense.
When internal date calculations result in a non-
is reduced to the last valid day of the month.
Refer to the PHP script Date_Math_Class_Test.php for examples of how these functions
can be used. If the test script is run via the console, the results of various functions are
echoed to the console.
This class was written such that the logical flow of each function is available in
pseudo code form in a text file Date_Math_Class.php.pseudo.
Naming convention: all functions begin with a capital letter;
all variables begin with $ and lower case first letter.
An inherant flaw exists with julian dates where years like 1700, 1800 and 1900 are not leap years
yet there is a PHP julian value for Feb 29 in those years. If you work with dates that span Feb 29
in a non-
Example: adding 2 days to 1900-
1900-
The depth count variable keeps track of how many internal function calls are active
and depth 1 serves to identify which function was called from the calling program.
Public functions included in this class are:
### Add Days -
function AddDays($days=0, $date=null, $fmt=null)
### Add Months -
function AddMonths($months=0, $date=null, $fmt=null)
### Add Weeks -
function AddWeeks($weeks=0, $date=null, $fmt=null)
### Add Years -
function AddYears($years=0, $date=null, $fmt=null)
### Age In Years -
function AgeInYears($date1=null, $date2=null)
### Date Is Valid -
function DateIsValid($date=null, $fmt=null, $which=1)
### Date To Julian -
function DateToJulian($date=null)
### Day Month Year -
function DayMonthYear($date=null)
### Day Of The Month -
function DayOfTheMonth($date=null)
### Day Of The Week -
function DayOfTheWeek($date=null)
### Day Of The Year -
function DayOfTheYear($date=null)
### Day Of The Year To Date -
function DayOfTheYearToDate($dayOfYear = 0, $year = null, $fmt=null)
### Difference In Days -
function DifferenceInDays($date1=null, $date2=null)
### Difference In Weeks -
function DifferenceInWeeks($date1=null, $date2=null)
### Difference In Years -
function DifferenceInYears($date1= null, $date2= null)
### Dow Month Day Year -
function DowMonthDayYear($date=null)
### End Of Next Month -
function EndOfNextMonth($date=null, $fmt=null)
### End Of Next Week-
function EndOfNextWeek($date=null, $fmt=null)
### End Of Next Year -
function EndOfNextYear($date=null, $fmt=null)
### End Of Prior Month -
function EndOfPriorMonth($date=null, $fmt=null)
### End Of Prior Week-
function EndOfPriorWeek($date=null, $fmt=null)
### End Of Prior Year -
function EndOfPriorYear($date=null, $fmt=null)
### End Of This Month -
function EndOfThisMonth($date=null, $fmt=null)
### End Of This Week -
function EndOfThisWeek($date=null, $fmt=null)
### End Of This Year -
function EndOfThisYear($date=null, $fmt=null)
### First Of Given Month -
function FirstOfGivenMonth($mon=null, $date=null, $fmt=null)
### First Of Next Month -
function FirstOfNextMonth($date=null, $fmt=null)
### First of Next Week -
function FirstOfNextWeek($date=null, $fmt=null)
### First Of Next Year -
function FirstOfNextYear($date=null, $fmt=null)
### First Of Prior Month -
function FirstOfPriorMonth($date=null, $fmt=null)
### First Of Prior Week-
function FirstOfPriorWeek($date=null, $fmt=null)
### First Of Prior Year -
function FirstOfPriorYear($date=null, $fmt=null)
### First Of This Month -
function FirstOfThisMonth($date=null, $fmt=null)
### First Of This Week -
function FirstOfThisWeek($date=null, $fmt=null)
### First Of This Year -
function FirstOfThisYear($date=null, $fmt=null)
### Get Last Error -
function GetLastError()
### Greater Date -
function GreaterDate($date1=null, $date2=null, $fmt=null)
### Is A Date -
function IsADate($date=null)
### Is The First -
function IsTheFirst($date=null)
### Julian To Date -
function JulianToDate($value=null, $fmt=null)
### Last Dow For A Month -
function LastDowForAMonth($dayOfWeek, $date=null, $fmt=null)
### Lesser Date -
function LesserDate($date1=null, $date2=null, $fmt=null)
### Maximum Date -
function MaximumDate($date1=null, $date2=null, $fmt=null)
### Minimum Date -
function MinimumDate($date1=null, $date2=null, $fmt=null)
### Month Day Year -
function MonthDayYear($date=null)
### Month Number -
function MonthNumber($mon=null)
### Month Str -
function MonthStr($date=null)
### N Days Before End Of The Month -
function NDaysBeforeEndOfTheMonth($n=0, $date = null, $fmt= null)
### Next Day Of The Week -
function NextDayOfTheWeek($dayOfWeek, $date=null, $fmt=null)
### Next First Of The Month -
function NextFirstOfTheMonth($date=null, $fmt=null)
### Next First Of The Year -
function NextFirstOfTheYear($date=null, $fmt=null)
### Next Nth Day Of The Month -
function NextNthDayOfTheMonth($n=1, $dayOfWeek, $date=null, $fmt=null)
### Next Nth Of The Month -
function NextNthOfTheMonth($n=0, $date=null, $fmt=null)
### Nth Of The Month -
function NthOfTheMonth($n=0, $date=null, $fmt=null)
### Number Of Days In A Month -
function NumberOfDaysInAMonth($date=null)
### Numeric Day Of The Week -
function NumericDayOfTheWeek($date=null)
### Numeric Month -
function NumericMonth($date = null)
### Numeric Year -
function NumericYear($date = null)
### Prior Day Of The Week -
function PriorDayOfTheWeek($dayOfWeek, $date=null, $fmt=null)
### Subtract Days -
function SubtractDays($days=0, $date=null, $fmt=null)
### Subtract Months -
function SubtractMonths($months=0, $date=null, $fmt=null)
### Subtract Weeks -
function SubtractWeeks($weeks=0, $date=null, $fmt=null)
### Subtract Years -
function SubtractYears($years=0, $date=null, $fmt=null)
### Use Exceptions -
function UseExceptions($state=null)
### Use Time Blocks -
function UseTimeBlocks($state=null)
### Week Number -
function WeekNumber($date=null)
### Ymd -
function Ymd($date=null)
### Ymd Array To Date -
function YmdArrayToDate($ymdArray=null, $fmt=null)
### Ymd String To Date -
function YmdStringToDate($yyyymmdd=null, $fmt=null)