'CDateTimeParser' or 'CTimestamp'

I have a requirement in my application, in user registration user should select timezone. I have another column in database for user table called ‘date_of_registration’.

I need help on the ‘date_of_registration’ column type to create it as date or int.

If the column type is date then i should store date value. If the column type is int then i should store timestamp value.

I should show ‘date_of_registration’ in the front end by using the timezone .

EX. if y user has to view ‘date_of_registration’ of x user, ‘date_of_registration’ value should convert to y’s timezone and then show the final date.

Now if my column is of datatype int which Yii function should i use whether ‘CDateTimeParser’ or ‘CTimestamp’,

and if my column is of datatype date which Yii function should i use whether ‘CDateTimeParser’ or ‘CTimestamp’,

What is the best way to do, and which class is more flexible for using.

Thanks in advance,

Pavan

You should store unix timestamps in your db, not strings.

You get the current timestamp in php function time() => use it when performing a registration.

For formatting dates and times from timestamps, use the class CDateFormatter.


<?php echo Yii::app()->dateFormatter->formatDateTime(time(), 'long', 'short'); ?>

The timezone which is used is Yii::app()->timeZone. You can change its default value in the main config file but ultimately each time a page is requested it should be set to the current user time zone in function init() of WebUser (extends CWebUser).