Home > Newsletter, Blog, and Other Topics > Topic

Yii calendar datepicker dateformat

Posted by research4oscar 
This forum is now read only. You can not log in or make any changes. Please use the new forum linked above.
As of March 14, 2011, this forum has been replaced and is permanently set to read-only mode. This means you can view any existing post but cannot open new posts or reply to existing ones. The new forum is located athttp://www.larryullman.com/forums/If you need to post a message, you'll need to register there. If you have to post in order to follow up on a thread started here, well, that's going to be a bit of a pain. I would recommend just posting the appropriate information, or copying the original text from here, or linking to your thread here. I apologize for the inconvenience but this purge will make for better forums in the long run. Thanks.
Yii calendar datepicker dateformat
November 24, 2010 07:18PM
Larry, do you have any examples where you successfully display/update a date field using any of the calendar extensions. Specifically I am trying to retrieve and display a date field in US standard date format (mm-dd-yyyy) and save it back to the database in mysql date format (yyyy-mm-dd). I've tried a few of the calendar extensions with no luck including jquery ui.

I am using yii-1.1.4 on a mac pro using MAMP installation.
# Apache 2.0.63
# MySQL 5.1.44
# PHP 5.2.13 & 5.3.2
Re: Yii calendar datepicker dateformat
November 24, 2010 08:36PM
Figured it out! I used the zii extension found at [www.yiiframework.com] since it does a call to Zii and does not require me to download anything. I copied the code they had in the example and replaced:
'name'=>'publishDate',

with the following:
'model'=>$model,
'attribute'=>'publishDate',

I then added the following code in the bottom of my model:
protected function beforeSave()
{
$this->publishDate=date('Y-m-d', strtotime($this->publishDate));
return TRUE;
}
protected function afterFind()
{
$this->publishDate=date('m-d-Y', strtotime($this->publishDate));
return TRUE;
}
Now my date field is retrieved using USA date format (mm/dd/yyyy) and I can update the time correctly to my field in the mysql table.
Re: Yii calendar datepicker dateformat
November 24, 2010 10:00PM
Glad you've got it working and thanks for sharing your solution.

Best Wishes,
Larry

Writer/Web Developer/Instructor
Forum Moderator