|
Posted by Andy Jeffries on 07/25/06 15:38
On Tue, 25 Jul 2006 09:46:02 -0400, Jerry Stuckle wrote:
>> I have a field in a database called DateRcvd. At present, it outputs in
>> my report in the yyyy-mm-dd format. I would like it to display in the
>> dd/mm/yy format. What is the easiest way to accomplish this?
>
> Depends on the database., But most have a function to format the default
> date to however you want. Check your database documentation.
>
> Otherwise you could reformat it in the php code - use substr() or a regex
> to get the year, month and day, then display them like you wish.
>
> Personally I prefer the database function.
Personally I prefer Kim André Akerø's solution, it's easier to read and
programmer time is (in *most* of the work I do) worth more than CPU time.
However, Kim's method is by far the slowest. To do 10,000 iterations of
each version:
$ ./test.php
strtotime/date = 0.5179 seconds
ereg = 0.0885 seconds
preg = 0.0435 seconds
substr = 0.0282 seconds
However, as I rarely do more than one or two conversions like this per
page impression, and they are on fairly low traffic sites on powerful
boxes (max is about 5M page impressions per month) I'll stick to most
readable :-)
Cheers,
Andy
--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos
[Back to original message]
|