Version: current

# Class sfDate

sfDate class.

A class for representing a date/time value as an object.

This class allows for chainable calculations using the sfTime utility class.

Package: sfDateTimePlugin
Author: Stephen Riesenberg <sjohnr@gmail.com>
Version: SVN: $Id$
Located at calendar_base/code/sfDate.class.php

## Methods summary

`public static `sfDate`` | # `getInstance( mixed $value = null )` Retrieves a new instance of this class. Retrieves a new instance of this class. NOTE: This is not the singleton pattern. Instead, it is for chainability ease-of-use. Example:
    echo sfDate::getInstance()->getFirstDayOfWeek()->addDay()->format('Y-m-d');
#### Parameters $value mixed timestamp, string, or sfDate object #### Returns ``sfDate`` sfDate
`public` | # `__construct( mixed $value = null )` Construct an sfDate object. Construct an sfDate object. #### Parameters $value mixed timestamp, string, or sfDate object
`public string` | # `format( mixed $format )` Format the date according to the `date` function. Format the date according to the `date` function. #### Returns `string` string
`public string` | # `date( mixed $format = 'd' )` Formats the date according to the `format_date` helper of the Date helper group. Formats the date according to the `format_date` helper of the Date helper group. #### Returns `string` string
`public string` | # `datetime( mixed $format = 'F' )` Formats the date according to the `format_datetime` helper of the Date helper group. Formats the date according to the `format_datetime` helper of the Date helper group. #### Returns `string` string
`public string` | # `dump( )` Format the date as a datetime value. Format the date as a datetime value. #### Returns `string` string
`public integer` | # `retrieve( integer $unit = `sfTime::DAY` )` Retrieves the given unit of time from the timestamp. Retrieves the given unit of time from the timestamp. #### Parameters $unit int unit of time (accepts sfTime constants). #### Returns `integer` the unit of time #### Throws `sfDateTimeException` sfDateTimeException
`public timestamp` | # `get( )` Retrieve the timestamp value of this sfDate instance. Retrieve the timestamp value of this sfDate instance. #### Returns `timestamp` timestamp
`public `sfDate`` | # `set( mixed $value = null )` Sets the timestamp value of this sfDate instance. Sets the timestamp value of this sfDate instance. This function accepts several froms of a date value: timestamp string, parsed with `strtotime` sfDate object #### Returns ``sfDate`` the modified object, for chainability
`public `sfDate`` | # `reset( )` Resets the timestamp value of this sfDate instance to its original value. Resets the timestamp value of this sfDate instance to its original value. #### Returns ``sfDate`` the reset object, for chainability
`public integer` | # `cmp( mixed $value )` Compares two date values. Compares two date values. #### Parameters $value mixed timestamp, string, or sfDate object #### Returns `integer` -1, 0, or 1
`public` | # `diff( mixed $value )` Gets the difference of two date values in seconds. Gets the difference of two date values in seconds. #### Parameters $value mixed timestamp, string, or sfDate object
`public `sfDate`` | # `__call( mixed $method, mixed $arguments )` Call any function available in the sfTime library, but without the ts parameter. Call any function available in the sfTime library, but without the ts parameter. Example:
    $ts = sfTime::firstDayOfMonth(sfTime::addMonth(time(), 5));
    // equivalent
    $dt = new sfDate();
    $ts = $dt->addMonth(5)->firstDayOfMonth()->get();
#### Returns ``sfDate`` the modified object, for chainability

### Magic methods summary

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -