CDateFormatter->formatDateTime() returns wrong date

I have a problem with the formatDateTime() function:

date_default_timezone_set('Europe/Berlin'); // not necessary if system has that timezone set already

echo Yii::app()->dateFormatter->formatDateTime('1942-02-15','medium','medium') ;

This returns the wrong date/time:

Feb 14, 1942 11:00:00 PM (instead of Feb 15, 1942 12:00:00 AM)

This issue only occurs with certain dates in certain timezones

(timezones have historical data, see:

In my application birthdates are entered together with user data, some dates will just be wrong when displayed.

Issue 161 reported that behaviour already, it was not really fixed though.

I created a new issue (470: where I also analyzed the problem further and suggested some solutions


I had and have a similar problem, see issue #161 (

I think it’s quite important that this works, especially as quite common dates are affected by this bug.

With default php functions we could get it working at least for all dates in the 32bit unix timestamp range, I think that is more useful than half-broken support for a bigger range of time.

Thanks. Will look into this.

I suggest rewriting CTimestamp for the time being based on the PHP functions that seem to work pretty well for PHP versions >= 5.2.

I am not sure though if on some systems there would still be a problem with dates before 1970 (negative unix timestamp). Maybe there could be an option in Yii to choose between two versions of CTimestamp. The ADOdb bugfixes should also be included then.

With this implementation of CTimestamp things seem to work ok:


class CTimestamp {

    public static function isValidTime($h,$m,$s,$hs24=true) {

        if($hs24 && ($h < 0 || $h > 23) || !$hs24 && ($h < 1 || $h > 12)) return false;

        if($m > 59 || $m < 0) return false;

        if($s > 59 || $s < 0) return false;

        return true;


    public static function isValidDate($y,$m,$d) {

        return checkdate($m, $d, $y);


    public static function getDate($d=false,$fast=false,$gmt=false) {

        if($gmt) {

            $tz = date_default_timezone_get();


            $result = getdate($d);


        } else {

            $result = getdate($d);


        return $result;


    public static function getTimestamp($hr,$min,$sec,$mon=false,$day=false,$year=false,$is_gmt=false) {

        if ($mon === false) return $is_gmt? @gmmktime($hr,$min,$sec): @mktime($hr,$min,$sec);

        return $is_gmt ? @gmmktime($hr,$min,$sec,$mon,$day,$year) : @mktime($hr,$min,$sec,$mon,$day,$year);