Version: current

# Class Date

Represents a date field. The field currently supports New Zealand date format (DD/MM/YYYY), or an ISO 8601 formatted date (YYYY-MM-DD). Alternatively you can set a timestamp that is evaluated through PHP's built-in date() function according to your system locale.

  Object
  ViewableData implements IteratorAggregate
  DBField
  Date

### Direct known subclasses

`SS_Datetime`

Package: sapphire\model
Located at sapphire/core/model/fieldtypes/Date.php

## Methods summary

`public` | # `setValue( mixed $value )` Set the value on the field. Optionally takes the whole record as an argument, to pick other values. Set the value on the field. Optionally takes the whole record as an argument, to pick other values. #### Parameters $value mixed $value #### Overrides `DBField::setValue`
`public` | # `Nice( )` Returns the date in the format dd/mm/yy TODO i18n formatting for NIce Returns the date in the format dd/mm/yy TODO i18n formatting for NIce
`public` | # `NiceUS( )`
`public` | # `Year( )` Returns the year from the given date Returns the year from the given date
`public` | # `Day( )` Returns the Full day, of the given date. Returns the Full day, of the given date.
`public` | # `ShortMonth( )` Returns the month Returns the month
`public` | # `DayOfMonth( )` Returns the date of the month Returns the date of the month
`public` | # `Month( )`
`public` | # `Long( )` Returns the date in the format 24 December 2006 Returns the date in the format 24 December 2006
`public` | # `Full( )` Returns the date in the format 24 Dec 2006 Returns the date in the format 24 Dec 2006
`public string` | # `Format( string $format )` Return the date using a particular formatting string. Return the date using a particular formatting string. #### Parameters $format string $format Format code string. e.g. "d M Y" #### Returns `string` The date in the requested format
`public` | # `FormatI18N( mixed $formattingString )` Return the date formatted using the given strftime formatting string. Return the date formatted using the given strftime formatting string. strftime obeys the current LC_TIME/LC_ALL when printing lexical values like day- and month-names
`public` | # `RangeString( mixed $otherDateObj )`
`public` | # `Rfc822( )`
`public` | # `Rfc2822( )`
`public` | # `Rfc3339( )`
`public` | # `Ago( )` Returns the number of seconds/minutes/hours/days or months since the timestamp Returns the number of seconds/minutes/hours/days or months since the timestamp
`public` | # `TimeDiff( )`
`public string` | # `TimeDiffIn( string $format )` Gets the time difference, but always returns it in a certain format Gets the time difference, but always returns it in a certain format #### Parameters $format string $format The format, could be one of these: 'seconds', 'minutes', 'hours', 'days', 'months', 'years'. #### Returns `string` string
`public` | # `requireField( )` Add the field to the underlying database. Add the field to the underlying database.
`public boolean` | # `InPast( )` Returns true if date is in the past. Returns true if date is in the past. #### Returns `boolean` boolean
`public boolean` | # `InFuture( )` Returns true if date is in the future. Returns true if date is in the future. #### Returns `boolean` boolean
`public boolean` | # `IsToday( )` Returns true if date is today. Returns true if date is today. #### Returns `boolean` boolean
`public` | # `URLDate( )` Returns a date suitable for insertion into a URL and use by the system. Returns a date suitable for insertion into a URL and use by the system.
`public` | # `days_between( mixed $fyear, mixed $fmonth, mixed $fday, mixed $tyear, mixed $tmonth, mixed $tday )`
`public` | # `day_before( mixed $fyear, mixed $fmonth, mixed $fday )`
`public` | # `next_day( mixed $fyear, mixed $fmonth, mixed $fday )`
`public` | # `weekday( mixed $fyear, mixed $fmonth, mixed $fday )`
`public` | # `prior_monday( mixed $fyear, mixed $fmonth, mixed $fday )`
`public static string` | # `past_date( mixed $fmonth, mixed $fday = 1, mixed $fyear = null )` Return the nearest date in the past, based on day and month. Automatically attaches the correct year. Return the nearest date in the past, based on day and month. Automatically attaches the correct year. This is useful for determining a financial year start or end date. #### Parameters $fmonth $fmonth int The number of the month (e.g. 3 is March, 4 is April) $fday $fday int The day of the month $fyear $fyear int Determine historical value #### Returns `string` Date in YYYY-MM-DD format
`public `FormField`` | # `scaffoldFormField( string $title = null, mixed $params = null )` Returns a FormField instance used as a default for form scaffolding. Returns a FormField instance used as a default for form scaffolding. Used by `SearchContext`, `ModelAdmin`, `DataObject::scaffoldFormFields()` #### Parameters $title string $title Optional. Localized title of the generated instance $params #### Returns ``FormField`` FormField #### Overrides `DBField::scaffoldFormField`

### Methods inherited from DBField

`ATT()`, `HTML()`, `HTMLATT()`, `JS()`, `LowerCase()`, `RAW()`, `RAWURLATT()`, `URLATT()`, `UpperCase()`, `XML()`, `__construct()`, `addToQuery()`, `create()`, `debug()`, `defaultSearchFilter()`, `exists()`, `forTemplate()`, `getName()`, `getValue()`, `hasValue()`, `nullValue()`, `prepValueForDB()`, `saveInto()`, `scaffoldSearchField()`, `setName()`, `setTable()`, `writeToManipulation()`

### Methods inherited from ViewableData

`ATT_val()`, `BaseHref()`, `CSSClasses()`, `ColumnBreak()`, `ColumnCalc()`, `ColumnNumber()`, `ColumnPad()`, `ColumnPos()`, `CurrentMember()`, `CurrentPage()`, `Debug()`, `Even()`, `EvenOdd()`, `First()`, `FirstLast()`, `HasPerm()`, `IsAjax()`, `JS_val()`, `Last()`, `Me()`, `Middle()`, `MiddleString()`, `Modulus()`, `MultipleOf()`, `Odd()`, `Pos()`, `RAW_val()`, `SQL_val()`, `ThemeDir()`, `ThemeName()`, `Top()`, `TotalItems()`, `XML_val()`, `__get()`, `__isset()`, `__set()`, `buildCastingCache()`, `cachedCall()`, `castingClass()`, `castingHelper()`, `castingHelperPair()`, `castingObjectCreator()`, `castingObjectCreatorPair()`, `customise()`, `defineMethods()`, `escapeTypeForField()`, `getField()`, `getIterator()`, `getSecurityID()`, `getXMLValues()`, `hasField()`, `i18nLocale()`, `iteratorProperties()`, `obj()`, `renderWith()`, `setCustomisedObj()`, `setField()`

### Methods inherited from Object

`__call()`, `__toString()`, `__wakeup()`, `addMethodsFrom()`, `addStaticVars()`, `addWrapperMethod()`, `add_extension()`, `add_static_var()`, `allMethodNames()`, `cacheToFile()`, `cacheToFileWithArgs()`, `clearCache()`, `combined_static()`, `createMethod()`, `create_from_string()`, `extInstance()`, `extend()`, `getCustomClass()`, `getExtensionInstance()`, `getExtensionInstances()`, `get_extensions()`, `get_static()`, `hasExtension()`, `hasMethod()`, `has_extension()`, `invokeWithExtensions()`, `is_a()`, `loadCache()`, `parentClass()`, `parse_class_spec()`, `remove_extension()`, `sanitiseCachename()`, `saveCache()`, `set_stat()`, `set_static()`, `set_uninherited()`, `stat()`, `strong_create()`, `uninherited()`, `uninherited_static()`, `useCustomClass()`

### Magic methods summary

## Properties summary

### Properties inherited from DBField

`$arrayValue`, `$defaultVal`, `$default_search_filter_class`, `$escape_type`, `$name`, `$tableName`, `$value`

### Properties inherited from ViewableData

`$casting`, `$customisedObject`, `$default_cast`, `$failover`, `$iteratorPos`, `$iteratorTotalItems`

### Properties inherited from Object

`$class`, `$extension_instances`, `$extensions`

[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. -