Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Email:

A Class for Validating and Formatting Dates

By Tony Marston
2005-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


 | Bookmark
Related Tutorials:
» Zend Framework Tutorial
» Port Scanning and Service Status Checking in PHP
» Web Database Access from Desktop Applications
» CubeCart 3.0 Installation and Configuration
» PHP Site Search Made Easy
» Installing and Configuring Drupal 6.1