tags:

views:

84

answers:

2

Hi, I'm planning on converting all the datetime data from a MySQL database to the format date('d-M-Y'). I'm thinking of doing it in the afterFind() callback but I'm wondering, how do detect the field type in CakePHP so I can create conditional statements?

Thanks in advance!

A: 

from http://php.net/manual/en/function.checkdate.php

<?php
function is_date( $str )
{
  $stamp = strtotime( $str );

  if (!is_numeric($stamp))
  {
     return FALSE;
  }
  $month = date( 'm', $stamp );
  $day   = date( 'd', $stamp );
  $year  = date( 'Y', $stamp );

  if (checkdate($month, $day, $year))
  {
     return TRUE;
  }

  return FALSE;
}
?>
John Boker
+2  A: 

Off the top of my head: Model::$_schema holds the schema for the database table, including the type of the field. This is auto-populated by Cake using SQL DESCRIBE queries. You can go through your query results in an afterFind() callback and access $this->_schema to find out the type of the field. Try debug($this->_schema); to see how it's structured.

deceze