Re: date & time conversion confusion
| From: | John McKown | Date: | Mon, 06 Nov 2000 20:39:44 +0000 |
| Subject: | Re: date & time conversion confusion | ||
| References: | 1 | Groups: | php.db php.general |
| Request: | Send a blank email to php-general+get-23976@lists.php.net to get a copy of this message | ||
How about getting MySQL to give you the information in the format that you
want? Suppose the date value you want is in the column named "thedate", do
something like:
SELECT DATE_FORMAT(thedate,"%M %d %Y) FROM tablename;
This would give something like "January 10 2000" Similiarly to change from
24 hour clock to 12 hour clock with an AM or PM suffix:
SELECT DATE_FORMAT(thetime,"%r") FROM tablename;
Look at
http://www.mysql.com/documentation/mysql/commented/manual.php?section=Date_and_time_function
Note that is a single line!
On Mon, 6 Nov 2000, Brian Tully wrote:
> hey folks -
>
> i'm having trouble figuring out how to convert an existing date & time into
> a more friendly format in PHP. I've used MySQL's date format which stores
> the values as YYYY-MM-DD. Now when I select these values from the database
> and display them on a web page I'd like to format them along the lines of
> MM-DD or Jan 01 or January 1 etc. I've looked into PHP's built-in functions
> time() mktime() getdate() etc, but none seem to work with existing values.
> Can anyone shed some light as to how I would go about doing this? I know in
> Perl there are tons of external libraries to do such things... are they
> available for PHP? Another issue is how I go about converting 24 hour time
> (00:00:00) into more friendly "XXam". Any help would be greatly
> appreciated.
>
> Many thanks,
> Brian
>
>
>