A Class for Validating and Formatting Dates
by Tony MarstonTonyMarston.net
Friday, 19th May 2006
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;
$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
$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
$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);
$tomorrow = $dateobj->addDays($today, +1);
$yesterday = $dateobj->addDays($today, -1);
Options:
Printer Friendly
Email Friend
About The Author:
I have been a software engineer, both designing and developing, since 1977. I have worked with a variety of 2nd, 3rd and 4th generation languages on a mixture of mainframes, mini- and micro-computers. I have worked with flat files, indexed files, hierarchical databases, network databases and relational databases. The user interfaces have included punched card, paper tape, teletype, block mode, CHUI, GUI and web. I have written code which has been procedural, model-driven, event-driven, component-based and object oriented. I have built software using the 1-tier, 2-tier, 3-tier and Model-View-Controller (MVC) architectures. After working with COBOL for 16 years I switched to UNIFACE in 1993, starting with version 5, then progressing through version 6 to version 7. In the middle of 2002 I decided to teach myself to develop web applications using PHP and MySQL.
I have been a software engineer, both designing and developing, since 1977. I have worked with a variety of 2nd, 3rd and 4th generation languages on a mixture of mainframes, mini- and micro-computers. I have worked with flat files, indexed files, hierarchical databases, network databases and relational databases. The user interfaces have included punched card, paper tape, teletype, block mode, CHUI, GUI and web. I have written code which has been procedural, model-driven, event-driven, component-based and object oriented. I have built software using the 1-tier, 2-tier, 3-tier and Model-View-Controller (MVC) architectures. After working with COBOL for 16 years I switched to UNIFACE in 1993, starting with version 5, then progressing through version 6 to version 7. In the middle of 2002 I decided to teach myself to develop web applications using PHP and MySQL.
