Page 1 of 1

Date and Timestamp problems

PostPosted: Wed Jun 06, 2012 7:38 am
by cookie720
Hi all!


Timestamp, it comes up unformatted 20120604012457 instead of 2012-06-04 01:24:57

I have the field set as:
Code: Select all
`EditedLast` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,

And I have tried this:
Code: Select all
function EditedLast__pullValue(&$record, $element){
if ($record->val('EditedLast') == NULL){
return "";
} else {
return date('Y-m-d H:i:s', strtotime($record->strval('EditedLast')));
}
}

to no avail...

ALSO

Im trying to make a date + 90 days
so grabs the date data from one date field, and autocompletes another field with that date + 90 days to it...
I have read that you can simply do
Code: Select all
date + 90
but not sure how to implement this...

Any ideas?!
Any help greatly appreciated.

Re: Date and Timestamp problems

PostPosted: Fri Jun 08, 2012 1:22 pm
by shannah
This looks like it's probably a bug. I have posted the bug at
http://bugs.weblite.ca/view.php?id=1038

As for your date + 90 question, it would depend on how the autocomplete should work. If you just need it to happen before save, then you'll want to implement the beforeSave() trigger in your table delegate class to perform the calculation.

e.g.
Code: Select all
public function beforeSave(Dataface_Record $record){
    if ( $record->valueChanged('date') ){
        $datestr = $record->strval('date');
        // If the date isn't formatted correctly you may need to do some formatting until the Xataface bug is fixed).
        $dateTime = strtotime($datestr);
        $newDate= strtotime('+90 days', $dateTime);
        $record->setValue('calc_date', date('Y-m-d H:i:s', $newDate));
    }
}



-Steve

Re: Date and Timestamp problems

PostPosted: Mon Jun 11, 2012 5:20 am
by cookie720
Thanks for your reply!
I tried yours and it works a treat however I also tried this:

Code: Select all
   function date1__display(&$record){
       return date('d/m/Y', strtotime($record->strval('date2'). " +90 day"));
    }

and it actually works!