Re: [PHP] Fw: Formatting dates (from MySQL)

2002-12-14 Thread Marco Tabini
You should be able to use strtotime() to transform the datetime string
into a UNIX timestamp, which you can then format back using date().
However, this is a very circuitous way--either use SQL to format it or,
if your DBMS supports it, have it returned already as a UNIX timestamp.
The actual SQL commands depend on which DBMS you actually use.


Marco
-- 

php|architect - The Magazine for PHP Professionals
The monthly magazine dedicated to the world of PHP programming

Check us out on the web at http://www.phparch.com!

---BeginMessage---
Hey there,

I was just looking at the date/time functions
(http://www.php.net/manual/en/function.time.php) and I can't seem to find a
function that can format a date that is supplied in the format of a DATETIME
column.

So, I was wondering, is there a function that can format it properly or
should I let the database handle the formatting (I'm really new to SQL, I
didn't come across anything to mod in the select statement yet). I could
ofcourse split it on space for a time and a date var and then split the date
on -'s for years, months and days but efficient is something else I think
:-) In the archives I saw some examples doing exactly that, but nothing with
a single function (unless home defined ofcourse).

Kind regards and TIA




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



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


RE: [PHP] Fw: Formatting dates (from MySQL)

2002-12-14 Thread John W. Holmes
 I was just looking at the date/time functions
 (http://www.php.net/manual/en/function.time.php) and I can't seem to
find
 a
 function that can format a date that is supplied in the format of a
 DATETIME
 column.
 
 So, I was wondering, is there a function that can format it properly
or
 should I let the database handle the formatting (I'm really new to
SQL, I
 didn't come across anything to mod in the select statement yet). I
could
 ofcourse split it on space for a time and a date var and then split
the
 date
 on -'s for years, months and days but efficient is something else I
think
 :-) In the archives I saw some examples doing exactly that, but
nothing
 with
 a single function (unless home defined ofcourse).

You can use the DATE_FORMAT() function in your SELECT query to format
the date however you want it. Or, you can use UNIX_TIMESTAMP() to pull
it out in the unix format and then use the PHP function date() to format
it. 

http://www.mysql.com/documentation/mysql/bychapter/manual_Reference.html
#Date_and_time_functions

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



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