Search code examples
phpdatetimetimestamptrim

How to trim the timestamp (i know, been asked before....)


My server response date/timestamp is in XML format, looks like this:

<au_updated_date>2018-02-04T13:32:58</au_updated_date>

All I want is 2018-02-04

Tried this but it displays nothing:

[date_format("au_updated_date","Y-m-d")]

Also tried some trim, string and substring functions to no avail :(

por favor?

EDIT:

Still not working :(

Perhaps this could be useful:

$response = curl_exec($ch);
$data = json_decode($response,true);

Then looping thru the response and displaying in an html table.

echo '<td align=left style="text-align:left">', ($data["results"][$i]["card"]["au_updated_date"]), '</td>';

Solution

  • omg, i got it!

    only took about 4 hours of banging on it lol

    instead of this:

    $au_dates = $au_record->getElementsByTagName( "au_updated_date" );
    $au_date = $au_dates->item(0)->nodeValue;
    

    I did this:

    $au_dates = $au_record->getElementsByTagName( "au_updated_date" );
    $au_date = $au_dates->item(0)->nodeValue;
    $new_date = date("Y-m-d", strtotime($au_date));
    

    Thanks Everyone, especially Andreas.