RE: mysql date question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



[snip]
I have a field in mysql as shown by describe contract;

| length_start         | date                | YES  |     | NULL    
|                |

Which stores it in the mysql format of YYYY-MM-DD.  However, I need the 
output of my select statement to show it in MM-DD-YYYY format.  I can 
select it to see the date in the field:

select length_start from contract where user_id = 1;
+--------------+
| length_start |
+--------------+
| 2006-01-12   |
+--------------+
1 row in set (0.00 sec)

so then I do my date_format() select statement, but it returns a NULL 
value.  Why?

select date_format('contract.length_start', '%m-%d-%Y') as length_start 
from contract where user_id = 1;
+--------------+
| length_start |
+--------------+
| NULL         |
+--------------+
1 row in set, 1 warning (0.00 sec)
[/snip]


Actually this is more a question for the MySQL list.

Start first by taking the ticks or quotes off of the column;

select date_format(contract.length_start, '%m-%d-%Y') as length_start 
from contract where user_id = 1;

You are essentially trying to turn that text string into a date, it will
not work.

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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux