A Class for Validating and Formatting Dates
By Tony Marston2005-04-16
Incrementing or Decrementing a Date
function addDays ($internaldate, $days)
// add a number of days (may be negative) to $internaldate (YYYY-MM-DD)
// and return the result in the same format
{
// ensure date is in internal format
$internaldate = $this->getInternalDate($internaldate);
// convert to the number of days since basedate (4714 BC)
$julian = GregoriantoJD(substr($internaldate,5,2)
,substr($internaldate,8,2)
,substr($internaldate,0,4));
$days = (int)$days;
$julian = $julian + $days;
// convert from Julian to Gregorian (format m/d/y)
$gregorian = JDtoGregorian($julian);
// split date into its component parts
list ($month, $day, $year) = split ('[/]', $gregorian);
// convert back into standard format
$result = $this->getInternaldate("$day/$month/$year");
return $result;
Tutorial pages:
|
|
|||||||||
You might also want to check these out:
|
Leave a Comment on "A Class for Validating and Formatting Dates"
You must be logged in to post a comment.
Link to This Tutorial Page!

