On Tue, 2004-02-24 at 13:29, Matthew Oatham wrote:
> You might already be fed up with my posts but I'm a complete PHP
> newbie and find these groups are the best way to learn! Anyway I have
> the database date in the format: yyyy-mm-dd hh:mm:ss e.g. 2004-02-24
> 07:57:59 but when in some situations I only want to show the user the
> date in the format dd-mm-yyyy what is the correct / best php function
> to use for this purpose ?

You can either use the date functions or regexps, I would recommend the
date functions, they may be a bit slower but they are more flexible and
easier to read:
$timestamp = strtotime('2004-02-24 07:57:59');
$date = date('d-m-Y', $timestamp);

Also, it would be best to try and get the date in a timestamp instead of
a formatted string, check if your database can do this.  If so then you
can skip the strtotime step above.  If you are using MySQL and the date
field is one of the date formats (ie. not char/varchar) take a look at
MySQL's date formatting functions[1].

Regards,
Adam

[1] http://www.mysql.com/doc/en/Date_and_time_functions.html

-- 
Adam Bregenzer
[EMAIL PROTECTED]
http://adam.bregenzer.net/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to