Jump to content

AtkDateAttribute

From NusaATK

Attribute: atkDateAttribute

API docs | Flags

List of other attributes

atkDateAttribute screenshot

Note that ATK uses an internal format for storing data in attributes. The date attribute stores the date value in an array with the 'year', 'month' and 'day' elements.

To convert a string value to the internal representation, e.g. when setting an initial value, use the attribute method parseStringValue.

  $attr = $this->getAttribute("orderdate");
  $record["orderdate"] = $attr->parseStringValue("2010-01-09");


Note that although atkdateattribute stores dates in array format the initial_values and edit_values functions will accept EITHER arrays or date strings !!

    function initial_values() {

        return array(

               "date1" => date(Y-m-d), // Today date string

               "date2" => array // Today ATK array
                   ("year" => date("Y"),
                    "month" => date("m"),
                    "day" => date("d"))

            );
    }

For 1st last days of say previous month -

    function initial_values() {

        // timestamp for 1 month ago
        $laststamp = mktime(0, 0, 0, date("m")-1, date("d"), date("Y"));

        return array(

            "from_date" => date("Y-m-1",$laststamp), // First day of previous month

            "to_date" => date("Y-m-t",$laststamp) // Last day of previous month

        );

    }