setDateFormats - cfsimplicity/spreadsheet-cfml GitHub Wiki

Allows the date masks used by the current library instance to be set.

setDateFormats( dateFormats )

Required arguments

  • dateFormats struct: including one or more of the following keys: DATE, TIME, TIMESTAMP, DATETIME.

Default masks

The following international date masks are used by default to read and write cell values formatted as dates:

  • DATE = yyyy-mm-dd
  • TIME = hh:mm:ss
  • TIMESTAMP = yyyy-mm-dd hh:mm:ss

An additional mask is used to output datetime values from the read() method into HTML or CSV formats:

  • DATETIME = yyyy-mm-dd HH:nn:ss

NB: Do not confuse DATETIME and TIMESTAMP. In general you should override the TIMESTAMP mask.

Overriding the defaults

You can override the defaults by

  1. passing in a struct including the value(s) to be overridden when instantiating the Spreadsheet component OR
  2. using the setDateFormats() method on an existing instance

Example 1: set formats on initialization

USDateFormat = { DATE: "mm/dd/yyyy" }
spreadsheet = New spreadsheetCFML.Spreadsheet( dateFormats=USDateFormat )

Example 2: set the formats on an existing instance

USDateFormat = { DATE: "mm/dd/yyyy" }
spreadsheet = New spreadsheetCFML.Spreadsheet()
spreadsheet.setDateFormats( USDateFormat )

Example 3: another option

USDateFormat = { DATE: "mm/dd/yyyy" }
spreadsheet = New spreadsheetCFML.Spreadsheet().setDateFormats( USDateFormat )