Changing a date format in PHP

Discussion in 'PHP' started by cocoonfxmedia, Jun 27, 2011.

  1. #1
    hi

    I can not figure out how to format a date in PHP.

    I have a form where a user will enter 01/10/2011 15:00

    I have a php script which is calling the date

    $date = $_POST["date"];

    I then can call this no problem, but I want to format the date to 01102011PM

    I have tried

    $date = $_POST["date"];
    $booking = date('ddmmyyy',$date);

    But this comes back 01011970

    Please could someone assist?
     
    cocoonfxmedia, Jun 27, 2011 IP
  2. ntomsheck

    ntomsheck Peon

    Messages:
    87
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    preg_replace("/\//",$_POST['date']);

    but sanitize your inputs.
     
    ntomsheck, Jun 27, 2011 IP
  3. cocoonfxmedia

    cocoonfxmedia Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you , preg_replace('/\//','',$_POST['date']) this is the exact string :eek:) which works.
     
    cocoonfxmedia, Jun 27, 2011 IP