3070 Posts in 869 Topics by 651 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 208 Views |
-
Update fields by date

30 December 2012 at 2:01pm
Hi, I have problem.
I try to write function to change fields in DB when date exceeds specific dateI have DataObject "Obiekt"
<?php
class Obiekt extends DataObject {
static $db = array(
'NrObiektu' => 'Int',
'Title' => 'Varchar(255)',
...
'Created' => 'Date',
'Waznosc' => 'Date', //for when to display the object
"Status" => "Enum('Oplacony, Nieoplacony')",
);static $indexes = array(
"URLSegment" => true
);public function getCMSFields() {
$fields = parent::getCMSFields();
...
return $fields;
}function onBeforeWrite() {
...
}}
I don't know how write this and where placed this (maybe to function or init() or other place?)
Maybe by DB:: ?Now I have to check date like this
$now = date('Y-m-d H:i:s');
$where = "Waznosc < '$now'";I want to when $where is true change field Status from Oplacony to Nieoplacony
Sorry for my bad English
-
Re: Update fields by date

8 January 2013 at 4:45pm Last edited: 8 January 2013 4:48pm
You need to convert the Database value into a unix timestamp so your conditional statement would be something like
strtotime($this->Waznosc) < time()
time() returns the current time as Unix Time Stamp so you don't need to worry about formatting it like with date()
As an aside strtotime() is also great for calculating things like strtotime('next Sunday') or strtotime('Yesterday')
| 208 Views | ||
|
Page:
1
|
Go to Top |


