Marmot Manual

Chapter 7. Miscellaneous

Table of Contents

Manipulating Dates
Getting User Information from LDAP

Manipulating Dates

Date manipulation can be challenge due to the fact that there are many common date entry formats and database date formats. Marmot's MU_Date class is designed to help with date manipulation.

An example

The MU_Date class is simple to use. At a minimum, it takes a date string and a format to use for parsing the date. For example:

$date = new MU_Date('4/15/2004', '%m/%d/%Y');

Details

An MU_Date object has the following attributes:

Table 7.1. MU_Date Attributes

AttributeDescription
$date->timestampContains the Unix timestamp of the current date value (seconds since the epoch: Jan 1, 1970 at 00:00:00 GMT)
$date->validTrue if the current date is valid, false otherwise
$date->stringContains the original string that was used to create the date
$date->yearContains the year value of the current date
$date->monthContains the month value of the current date
$date->dayContains the day value of the current date
$date->hourContains the hour value of the current date
$date->minuteContains the minute value of the current date
$date->secondContains the second value of the current date

It has the following methods:

Table 7.2. MU_Date Methods

MethodDescriptionParametersReturns
$date->format($format)Sets the format of the objectformat - a valid date format (described below)the current format
$date->year($year)Sets the year of the objectyear - a valid year valuethe current year
$date->month($month)Sets the month of the objectmonth - a valid month value (1-12)the current month
$date->day($day)Sets the day of the objectday - a valid day value (1-31)the current day
$date->hour($hour)Sets the hour of the objecthour - a valid hour valuethe current hour
$date->minute($minute)Sets the minute of the objectminute - a valid minute valuethe current minute
$date->second($second)Sets the second of the objectsecond - a valid second valuethe current second
$date->parse_date($date, $format)Parses the date uses the format specified. It sets all object attributes to the newly parsed datedate - a string representing a date format - optional, a valid format string, defaults to the value of the object formattrue if the value successfully parsed as a valid date, false otherwise
$date->compare($compare_date)Compares the current date object value to the value of the compare_date objectcompare_date - another date object0 if the dates are equal, 1 if this date is greater than the compare date (ie, this is after that), -1 if this date is less than the compare date (ie, this is before that)
$date->calculate($interval)Calculates the difference using the current date and intervalinterval - the interval string, any string acceptable to the PHP strtotime functionthe new date formatted using the the format of the current object
$date->format_date($format)Formats the current date using the specified formatformat - optional, a valid format, defaults to the current object formatthe formatted date

The following format specifiers are supported:

Table 7.3. Date Format Specifiers

SpecifierMeaning
%Yfour digit year
%ytwo digit year
%mnumeric month (1-12)
%dnumeric day
%Hhour (24 hour clock assumed)
%Mminute
%Ssecond
%Dshortcut for %m/%d/%y
%Tshortcut for %H:%M:%S