Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8965195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:45:45+00:00 2026-06-15T16:45:45+00:00

I am using CTimeStampBehaviour for setting create_time and update_time resetting create_time with afterFind() in

  • 0

I am using CTimeStampBehaviour for setting create_time and update_time resetting create_time with afterFind() in model, Basically I am setting the format of date to be displayed on the front end. But this does not work as create_time is sent 0000-00-00 00:00:00 on using model’s afterFind(). It works fine when I comment afterFind() in model.

I have used this function in my model:

public function behaviors(){
return array(
    'CTimestampBehavior' => array(
        'class' => 'zii.behaviors.CTimestampBehavior',
        'createAttribute' => 'create_time',
        'updateAttribute' => 'update_time',
        'setUpdateOnCreate'=> true,
    )
);
}

I have seen the documentation on CTimeStampBehavior class on yii site, it has a reference to afterFind() inheritence but does not suggest how to use it. I am using afterFind() in model like this:

protected function afterFind() {
parent::afterFind();
$this->create_time = Yii::app()->dateFormatter->formatDateTime(
        CDateTimeParser::parse(
            $this->create_time, 'yyyy-MM-dd hh:mm:ss'
        ), 'short', 'short'
    );
return true;
}

Can anyone suggest why the create_time is being zero filled when using afterFind()?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:45:46+00:00Added an answer on June 15, 2026 at 4:45 pm

    create_time will be zero filled when you save the model after loading it and afterFind() changed the value of create_time to a formatted date.
    This is because when you save your model now your are trying to send the formatted value to the database which does not understand the format and set the value to 0000-00-00 00:00:00.

    When you implement an afterFind() method to change values format, you have to implement a beforeSave() method to set the value back to a format that can be understood by the database.

    It is generally a bad idea to format values directly on the model. When you are doing strict MVC it is the job of the View to format your Date correctly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using import datetime in python, is it possible to take a formatted time/date string
Using RestKit 0.10.1, I have objects served similar to this json format: {objects: [
Using jQuery I'm trying to obtain the rotation state of an object but in
Using C# How can I show a document in richtextbox without scrollbars, But I
Using hostfile in C# I can block websites but I couldn't unblock them. String
Using Python, I'm trying to connect to my AppEngine app's remote_api handler, but I
Using JNotify in project and it fulfill my all requirements, but some times it
Using C#, I want to format a decimal to only display two decimal places
Using Rails 3, but I guess doesn't matter. I put this in the template
Using C#, I want to show the image in the Access column but failed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.