Re: mysql date question

From: Date: Thu, 03 Jan 2008 20:49:04 +0000
Subject: Re: mysql date question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-266587@lists.php.net to get a copy of this message
On Thu, January 3, 2008 8:30 am, Adam Williams wrote: > 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) There is not PHP in this question. But to save you subscribing/posting/unsubcribing to the MySQL list: You put apostrophes on 'contract.length_start' which makes it a literal DATE. MySQL silently ignores such a stupid-looking date, and makes it NULL. Take away the apostrophes on the FIELD NAME and all will be good. -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/from/lynch Yeah, I get a buck. So?

« previous php.general (#266587) next »