A Class for Validating and Formatting Dates
By Tony Marston2005-04-16
Using this Class in Your Code
In order to use any of the functions in this class you will need code similar to the following:
First you must create an object from the class (or instantiate a class instance in OOP speak):
require 'date.class.in';
$dateobj = new DateClass;
This code will take a date in external (user) format and convert it to internal (database) format, with any error messages being inserted into the $errors array.
if (!$internaldate = $dateobj->getInternalDate($_POST['date']) {
$errors = $dateobj->errors;
} // if
This code will take a date in internal (database) format and convert it to external (user) format, with any error messages being inserted into the $errors array.
if (!$externaldate = $dateobj->getExternalDate($internaldate]) {
$errors = $dateobj->errors;
} // if
This code will take a date and obtain the dates for the previous and next days.
$today = date('Y-m-d');
$tomorrow = $dateobj->addDays($today, +1);
$yesterday = $dateobj->addDays($today, -1);
Tutorial Pages:
» A Class for Validating and Formatting Dates
» Defining the Class to Handle Dates
» Display date to the User
» Incrementing or Decrementing a Date
» Using this Class in Your Code
» Summary
