Re: Usinf DATE_FORMAT Expression in findAll()

2007-07-31 Thread keys71


...or is the usage of an 'afterFind' - function the right method of
resolution (because it works)?

function afterFind($results) {
foreach ($results as $key = $val) {
if ( isset($val['Event']['validity_date']) ) {
   $dates = explode(-, $val['Event']['validity_date']);
   $results[$key]['Event']['validity_date_fmt'] =
$dates[2]...$dates[1]...$dates[0];
}
 }
  return $results;
   }




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Usinf DATE_FORMAT Expression in findAll()

2007-07-30 Thread keys71

Hi folks,

maybe somone can help me.
I want to convert a date field (mySql) in german date format.

The mysql query would be:

...DATE_FORMAT(validity_date, '%d.%m.%Y') as formatted_date

I tried the following as test without formatting inside the controller
and index() - function

$this-set( 'events', $this-Event-findAll(NULL,
array(*,Event.validity_date as validity_date_fmt)) );

It works fine as expected:

Array
(
[0] = Array
(
[Event] = Array
(
[id] = 3
[title] = Testevent #1
[description] = Longdesc .
[category_id] = 1
[user_id] = 1
[validity_date] = 2007-10-01
[created] = 2007-07-30
[validity_date_fmt] = 2007-10-01
)
..

And now the formatting:
$this-set( 'events', $this-Event-findAll(NULL,
array(*,DATE_FORMAT(Event.validity_date, '%d.%m.%Y') as
validity_date_fmt)) );

Giving the following results:
Array
(
[0] = Array
(
[Event] = Array
(
[id] = 3
[title] = Testevent #1
[description] = Longdesc .
[category_id] = 1
[user_id] = 1
[validity_date] = 2007-10-01
[created] = 2007-07-30
)


[0] = Array
(
[validity_date_fmt] = 01.10.2007
)

)
..

What do i have to change to get the validity_date_fmt as array-key to
the Event-Array ?

Thanks in advance,

Robert


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---