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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:13:50+00:00 2026-06-13T21:13:50+00:00

I have a birthdate field which is optional after inserting a record into clients

  • 0

I have a birthdate field which is optional after inserting a record into clients table.

the default value will is “000-00-00” after insert.

Now, I want to edit the record in the table and would like to get the value of the birth_date field into three dropdown list.

The three dropdown list are Day, Month, and Year.

If there is no birthdate the selected value of the three dropdown should be “Day”, “Month”, and “Year”.

I tried the following code and don’t know if this is the best way.

$dateValue = '0000-00-00';
$year = explode("-", $dateValue);

if ($year[0] == "0000") {
    $selected_year = "Year";
            $selected_month = "Month";
            $selected_day = "Day";
}else{
    $selected_year = date("Y",strtotime($user['birth_date']));
}

If there is a better way for this, please let me know.

btw, I’m using codeigniter.

  • 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-13T21:13:51+00:00Added an answer on June 13, 2026 at 9:13 pm

    I think you are doing your test too late, it is much simpler to do it directly on $dateValue. Also, you can simplify the code by making use of the list function:-

    $dateValue = '0000-00-0';
    if($dateValue == '0000-00-00'){
        $values = array('Year', 'Month', 'Day');
    } else {
        $values = explode('-', $dateValue);
    }
    list($selected_year, $selected_month, $selected_day) = $values;
    
    var_dump($selected_year);
    var_dump($selected_month);
    var_dump($selected_day);
    

    Gives the following output:-

    string 'Year' (length=4)
    string 'Month' (length=5)
    string 'Day' (length=3)
    

    Changing the first line to:-

    $dateValue = '2012-11-3';
    

    Gives:-

    string '2012' (length=4)
    string '11' (length=2)
    string '3' (length=1)
    

    Personally, I would hide this all away in a function to improve readability:-

    function getValues($dateValue = '0000-00-00'){
        if($dateValue == '0000-00-00'){
            $values = array('Year', 'Month', 'Day');
        } else {
            $values = explode('-', $dateValue);
        }
        return $values;
    }
    

    Then use it like this:-

    list($selected_year, $selected_month, $selected_day) = getValues('2012-11-03');
    
    var_dump($selected_year);
    var_dump($selected_month);
    var_dump($selected_day);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class User with one field called birthDate which is a java.sql.Date
I have table in which I have birthdate , age location and Score and
I have a birthday field in my database which has a date value as
I have a table of users which has a date field for their birthday:
I have a Birthdate field with theses values: 28 Juillet 1982 (I want this
If I have a datetime field (like Birthdate) in Sql Server, and I want
I have a table of users with a field birthday (DATE). Currently, I select
I have a nice clean UI within a table view which has a few
I have a string field dob which has birthdates in various formats e.g. dob
I have a json form field which has a check box as coded :

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.