Re: [PHP-DB] MySql, PHP, and Dates

2003-03-30 Thread Jason Wong
On Sunday 30 March 2003 11:11, Bruce Feist wrote:

 I wonder why the PHP/MySql interface doesn't simply return dates as
 dates instead of strings.  *frowns*

How do you mean? PHP doesn't have a date type.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-db
--
/*
Blutarsky's Axiom:
Nothing is impossible for the man who will not listen to reason.
*/


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



Re: [PHP-DB] MySql, PHP, and Dates

2003-03-30 Thread Bruce Feist
Jason Wong wrote:
On Sunday 30 March 2003 11:11, Bruce Feist wrote:

I wonder why the PHP/MySql interface doesn't simply return dates as
dates instead of strings.  *frowns*
How do you mean? PHP doesn't have a date type.

Ummm That's a good reason!  As I said, I'm a newbie to PHP, and 
somewhere along the line I got the idea that there was an actual date 
data type.  I don't know where I got that idea; the book I've been using 
certainly doesn't say that it does, although I thought I did.

It's times like this that I wish that I had smaller feet or a larger 
mouth, to make it easier to remove the one from the other!

Thanks.

Bruce Feist

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


Re: [PHP-DB] MySql, PHP, and Dates

2003-03-29 Thread Bruce Feist
I originally wrote:

when I retrieve a date from MySQL into PHP, it shows up as a string instead of a date data type
 What's the best way of controlling date format?

John W. Holmes replied:

If you want a Unix timestamp, which is compatible with the date()
function in PHP, then use the UNIX_TIMESTAMP() function in your SQL.
This seems to be the ideal solution.  Thanks, John, and also those of 
you who responded via private e-mail.

I wonder why the PHP/MySql interface doesn't simply return dates as 
dates instead of strings.  *frowns*

Bruce Feist

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


RE: [PHP-DB] MySql, PHP, and Dates

2003-03-28 Thread John W. Holmes
 I'm experienced with SQL, but new to MySql and PHP, which I'm using
 together to create a dynamic web site.  Right now, I'm having minor
 difficulties with date formatting.  It seems that when I retrieve a
date
 from MySQL into PHP, it shows up as a string instead of a date data
 type, with format -MM-DD HH:MM:SS.  Is there any way that I can
get
 it returned as a PHP date instead?  Also, exactly what is it that
 controls the output format of the date as a string?  Is PHP somehow
 requesting that MySql return the date as a string, or is it getting a
 date from MySql and then converting it to a string on the PHP side?
 
 What's the best way of controlling date format?  Obviously, I could
use
 string operators to extract the year, month, and day and do whatever I
 want to with them, but that's sensitive to how PHP and/or MySql are
 configured, I assume; it would be better for me to request the date in
a
 specific form (ideally one taken from operating system preferences).

A couple different ways you can handle this. To format the timestamp
from -MM-DD HH:MM:SS to something else, you can use the
DATE_FORMAT() function within your SQL. It works almost exactly like the
date() function in PHP. 

If you want to get the output from MySQL as an integer, you can use
SELECT column+0 which will return the timestamp in a MMDDHHMMSS
format. 

If you want a Unix timestamp, which is compatible with the date()
function in PHP, then use the UNIX_TIMESTAMP() function in your SQL.

You could also use the strtotime() function in PHP to take the MySQL
timestamp and convert it to a Unix timestamp. 

---John W. Holmes...

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



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