need help on date format

Discussion in 'PHP' started by cri8bat, Oct 6, 2009.

  1. #1
    Hi all,

    I am using dreamweaver to create a simple dynamic page.

    I am using php with phpmyadmin.

    on phpmyadmin the date datatype is default to YYYY-mm-dd

    I createa a site backend where the admin can insert a record to the databse. On of the fields is date of birth.

    I have a textfield on the form where the user will enter the date. the current format is the defaut of phpmyadmin (YYYY-mm-dd). I want the user to be able to enter dd/mm/yyyy.

    with 3 textfields (dd) / (mm) / (yyyy)

    can some1 help me on this, pls. :)

    thanks in advance
     
    cri8bat, Oct 6, 2009 IP
  2. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    $date = explode('/', $_POST['date']);
    if (count$date) == 3) {
      $mysql_date = $date[2] . '-' . $date[1] . '-' . $date[0];
    } else {
      //incorrect input
    }
    PHP:
     
    premiumscripts, Oct 6, 2009 IP
  3. orionoreo

    orionoreo Peon

    Messages:
    145
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i recommend using time stamps... better for storing and easier to change format

    when you get the input you'll do something such as

    $date_of_birth = mktime(0,0,0,$month, $day, $year);

    store it and then you can output as

    echo date('Y-m-d', $date_of_birth);
     
    orionoreo, Oct 6, 2009 IP