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 9092393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:50:06+00:00 2026-06-16T22:50:06+00:00

In my database, I have a date of birth ( dob ) field that

  • 0

In my database, I have a date of birth (dob) field that is of type date.
When I create model from my table, it creates one attribute as dob for
me.

So when I generate my form from my model, it has one field that can collect
the user’s date of birth. What I want to have is to have 3 dropdown elements
each for day month and year. then when I submit my form, they all get bundle
up together as dd-mm-yyyy and get populated to my model attribute “dob“

At this point I can’t figure out how to do it using Yii form since the model
gets passed to the view, how can I find a way to accomplish this. So to recap,

-I want to have only one field in my User table for dob as date type
-I want to have 3 dropdowns in my Yii generated form that at submit time they
form my dob and populate it in the $model->user_dob

  • 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-16T22:50:07+00:00Added an answer on June 16, 2026 at 10:50 pm

    That is really strange… I did a similar thing earlier today. I find that people don’t use the date picker correctly so I prefer to use drop downs.

    Declare virtual fields in your model for month, day, and year, add validation rules, then create a drop down for each.

    Example of creating the drop down lists:

    echo CHtml::activeDropDownList($model, 'month', $monthsArray);
    echo CHtml::activeDropDownList($model, 'day', $daysArray);
    echo CHtml::activeDropDownList($model, 'year', $yearsArray);
    

    You need to fill the arrays with the months, days, and years you want to give as options. This seems to be outside the scope of your question but I’ll include example functions for doing that at the end, just in case.

    Then in your form controller, when you do:

    $model->attributes = $_POST['User'];
    

    those values should be added to $model->month, $model->day, and $model->year.

    Then all you have to do is format it in the Date format like this:

    $model->dob = $model->year . '-' . $model->month . '-' . $model->day;
    

    and save the model.

    — extra: example of month, day, year arrays —
    These aren’t really the best way of doing it, but for my purposes they have worked fine.

        public function getMonthsArray()
        {
            for($monthNum = 1; $monthNum <= 12; $monthNum++){
                $months[$monthNum] = date('F', mktime(0, 0, 0, $monthNum, 1));
            }
    
            return array(0 => 'Month:') + $months;
        }
    
        public function getDaysArray()
        {
            for($dayNum = 1; $dayNum <= 31; $dayNum++){
                $days[$dayNum] = $dayNum;
            }
    
            return array(0 => 'Day:') + $days;
        }
    
        public function getYearsArray()
        {
            $thisYear = date('Y', time());
    
            for($yearNum = $thisYear; $yearNum >= 1920; $yearNum--){
                $years[$yearNum] = $yearNum;
            }
    
            return array(0 => 'Year:') + $years;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a date of birth field in the database which is of datatype
I have created one web-form that contains controls to add name, date of birth,
I have Database with date field. I see the time like: 1900-01-01 13:38:00.000 How
In mysql database i have this column called: Name: Date Type: datetime I have
i have database table like this +-------+--------------+----------+ | id | ip | date |
I have a database with a large number of records that are Date/Time stamped.
In my SQL Server database schema I have a data table with a date
I have a huge database (800MB) which consists of a field called 'Date Last
I have two users in my database whose birth date is set to: 1985-01-26
Hello i have a JSP page that displays records from animal table in my

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.