Dates are retrieves from the SQL database as strings and represented as such in the Yii generated models.
Conversion functions - including the ones used by CFormatter::formatDate, CFormatter::formatTime, and, CFormatter::formatDateTime - require a numeric representation of the date/time.
I extended the CFormatter class for many reasons, for instance to do automatic scale conversion, and I ended up modifying the date and time formatting methods.
I basically detect if the provided parameter is a string in which case I assume that the value represents a date that I can convert using strtime. I then feed the resulting value to the original conversion implementation.
This is a sample extension of the CFormatter class:
<?php
class MyFormatter extends CFormatter {
public function formatDate($value) {
if(is_string($value)) {
$value = strtotime($value);
}
return parent::formatDate($value);
}
public function formatTime($value) {
if(is_string($value)) {
$value = strtotime($value);
}
return parent::formatTime($value);
}
public function formatDateTime($value) {
if(is_string($value)) {
$value = strtotime($value);
}
return parent::formatDateTime($value);
}
}
?>