how to insert month,day,year as a single value in the database

Discussion in 'PHP' started by kumar84, Jul 16, 2007.

  1. #1
    hai friends

    Iam having three seperate combo (dropdown) box In these Iam having Month,Day,Year

    If i select the first combo box it shows the month (january, Febuary)
    If i select the second combo box it shows the day(1,2,3)
    if i select the third combo box it shows the year(1999,2000)

    This is what i have done

    Now i need is
    in the database i have dateofbirth(date (datatype)) as a single column when i select this 3 combo box it should insert in this dateofbirth column as a single value in the format of
    Dec 27 1984


    So i need Php code for this

    can anybody help this

    Thanks in advance
     
    kumar84, Jul 16, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    $date = date('M d Y', mktime(0, 0, 0, $_POST['month'], $_POST['day'], $_POST['year']));
    
    PHP:
    I would store just the timestamp though. This way it's easier to work with later, and you can sort the dates, etc...
     
    nico_swd, Jul 16, 2007 IP
  3. srobona

    srobona Active Member

    Messages:
    577
    Likes Received:
    57
    Best Answers:
    0
    Trophy Points:
    88
    #3
    If you want to keep the format same, you may have to change the datatype to varchar/text/blob, since "Dec 27 1984" is a string.

    However, try this:
    <?
    $date = $_POST['month']." ".$_POST['day']." ".$_POST['year'];
    ?>

    If you want to save data without changing the datatype, the format will be like: 1984-12-27, and you need to change the month values (Jan->1, Feb->2,...)

    to do this in php:
    <?
    $date = $_POST['year']."-".$_POST['month']."-".$_POST['day'];
    ?>

    Let me know if u get help from above information :)
     
    srobona, Jul 16, 2007 IP