Question

I'm using http://finance.yahoo.com/d/quotes.csv?s= to grab a company's stock prices and imbedding in their site. I have 2 issues with it:

  1. Is it possible to reformat the date? It's currently returned MM/DD/YYYY, and it would be great if I were able to reformat to return DD/MM/YYYY. Is this possible?

  2. Also, the date is being returned with quotation marks, to literally return "MM/DD/YYY". I'd really love to get rid of these quotation marks.

Any ideas?

Many TIA!


EDIT:

I'm using the following code:

<?php
$asxcode = 'TDO';
$price = file_get_contents('http://finance.yahoo.com/d/quotes.csv?s=' . $asxcode . '.AX&f=l1');
$date = file_get_contents('http://finance.yahoo.com/d/quotes.csv?s=' . $asxcode . '.AX&f=d1');
echo '$' . $price . '<br/>' . $date;
?>
Was it helpful?

Solution

Try this:

//get rid of the quotation marks
$yahoo_date = trim($yahoo_date, '"');

//will recognize yahoo's format and convert to a timestamp 
$timestamp = strtotime($yahoo_date); 

//you can now format it in any way you want
$reformatted_date = date('d/m/Y', $timestamp);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top