Help converting specific string to timestamp

Discussion in 'PHP' started by liam1412, Oct 22, 2011.

  1. #1
    Hi

    Can anyone help me with the following

    I am scraping some content (legally) and I need to convert the date to a timestamp.

    It is presented in this format


    September 22nd, 2011 11:05 AM


    Can anyone help.
     
    liam1412, Oct 22, 2011 IP
  2. ngcoders

    ngcoders Active Member

    Messages:
    206
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #2
    use strtotime

    $time = strtotime('September 22nd, 2011 11:05 AM'); //convert
    echo date('r',$time); // check
     
    ngcoders, Oct 22, 2011 IP
  3. liam1412

    liam1412 Active Member

    Messages:
    387
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #3
    I feel really foolish now

    I thought strtotime wouldn't work due to the comma after September,
     
    liam1412, Oct 22, 2011 IP
  4. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #4
    From the PHP manual:

    "strtotime — Parse about any English textual datetime description into a Unix timestamp"

    They're pretty broad about the meaning of "any" - even "next Thursday" will produce a valid time value.
     
    Rukbat, Oct 24, 2011 IP