Mathew,

Great that they're backwards from one another, isn't it?

The regular expression wizards probably have some marvellous trick up their 
sleeve, and Manuel Lemos probably has a class that will do this. You can do 
it yourself by using substring functions to extract the parts of the date, 
rearrange it and then, if you wish, use a couple of lookup arrays to fetch 
months and extensions like "st rd ..".

But better that, aren't there date extraction functions in MySQL you can 
use in your select statement?

Or, even better, and this is a personal crusade, "Let's train the world to 
use a logical date format: yyyy-mm-dd!!" (Isn't this an ISO Standard, which 
should be acceptedin the UK and in Europe?)

Here's some extraction stuff I messed around with about a year 
ago...$dtAuctionStart is yyyymmdd MySql date, no hyphens.

Some messing about with dates <br>
=============================<br>


echo $dtAuctionStart, "<br>";
echo date ("Y-m-d", $dtAuctionStart ), "<br>";
//$strDate = $dtAuctionStart ;
echo "dtAuctionStart : $dtAuctionStart";

$year = substr ($dtAuctionStart, 0, 4);
$month = substr( $dtAuctionStart, 4, 2 );
$day = substr ($dtAuctionStart, 6, 2 );
Echo "dtAuctionStart in m-d -y : $month-$day-$year <br>";

$workdate = getdate( $dtAuctionStart );
echo " Workdate Year:", $workdate["year"],"<br>";


Ereg Stuff <br>
==========<br>

if (ereg ("([0-9]{4})([0-9]{1,2})([0-9]{1,2})", $dtAuctionStart, $regs))
{
echo "Auction Start: $regs[1]-$regs[2]-$regs[3] <br><br>";
}
else
{
echo "Bad date format. <br>";
}


Have fun - Miles

At 01:57 PM 5/23/01 +0100, Matthew Ralston wrote:
>I've got a date stored in a MySQL database in a "DATE" field, so it is
>stored as "2001-05-21". How do I convert that into a more friendly date like
>"21 May 2001" or even "21st May 2001" for display on a web page?
>
>I've tried
>
>print date("jS F Y", $dbtable[date]);
>
>but I always get "1st January 1970" because I don't know how to convert the
>MySQL date into a PHP timestamp.
>
>Can someone tell me how to do it please?
>
>--
>Thanks,
>
>Matt
>[EMAIL PROTECTED]
>< www.mralston.co.uk />
>
>
>
>
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to