UK Dates: 05/01/2007 is 5th jan NOT 1st May!

Discussion in 'PHP' started by Hade, Nov 16, 2007.

  1. #1
    Hi,
    My user enters a UK into a text box on the web page.
    If they enter 05/01/2007 PHP will think it's the 1st may, when it's 5th January.

    so formatting the text as full month names will display the wrong month.

    How can I tell PHP that the first part is the day, then the month etc.

    Thanks
     
    Hade, Nov 16, 2007 IP
  2. Noddegamra

    Noddegamra Peon

    Messages:
    1,013
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Have the day, month and year in select/drop down boxes.

    Then join them at the end :)

    
    $publish_day = $_POST['publish_day'];
    $publish_month = $_POST['publish_month'];
    $publish_year = $_POST['publish_year'];
    $publish_date_combine = $publish_year . '-' . $publish_month . '-' . $publish_day;
    $publish_date = strtotime($publish_date_combine);
    
    PHP:
    Then when you want to output the data again just do


    
    $date = date('d-m-Y', $publish_date);
    
    PHP:
     
    Noddegamra, Nov 16, 2007 IP
    Hade likes this.
  3. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #3
    or try this

    $arrDate = explode('/',$dateField);
    date('F d, Y', mktime(0,0,0 $arrDate[1], $arrDate[0], $arrDate[2]);

    Note: assuming $dateField is the value of the field coming from the post
     
    serialCoder, Nov 16, 2007 IP
    Hade likes this.
  4. Hade

    Hade Active Member

    Messages:
    701
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    90
    #4
    Both excellent responses, thank you!
     
    Hade, Nov 16, 2007 IP