You are here: Re: Format datetime with query? « PHP SQL « IT news, forums, messages
Re: Format datetime with query?

Posted by Rik on 08/24/07 16:46

On Fri, 24 Aug 2007 18:35:05 +0200, MattMika <mattmika@hotmail.com> wrot=
e:

> On Fri, 24 Aug 2007 01:54:24 -0700, Captain Paralytic
> <paul_lautman@yahoo.com> wrote:
>
>> On 24 Aug, 03:51, mattm...@hotmail.com wrote:
>>
>> | what I've tried so far returns errors.
>>
>> Care to share the errors!
>
> Ok, I uncommentd trace(fe.fault.faultstring) in my actionscript and
> the error turned out to be too few parameters to sprintf.
>
> I have this working in a test php file:
> $sql =3D "SELECT DATE_FORMAT(events_date, '%b.' ' %D,' ' %Y') as Date,=

> events_title as Event, events_description as Description FROM events
> ORDER BY Date ASC";
>
> So now I know, yes, I can do what I was looking to do.
>
> My original query in the php class for amfphp is this:
> $sql =3D sprintf("SELECT format_date as Date, events_title as Event,
> events_description as Description FROM events ORDER BY Date ASC");
>
> This works fine.
>
> My new query in the php class is this:
> $sql =3D sprintf("SELECT DATE_FORMAT(events_date, '%b.' ' %D,' ' %Y') =
as

Huh?
'%b. %D, %Y' seems OK to me, why bother breaking it apart (which would =

result in an error in mysql).

> Date, events_title as Event, events_description as Description FROM
> events ORDER BY Date ASC");
>
> The DATE_FORMAT() is somehow messing with the sprintf so I need to
> figure out why and Im good. Off to find my solution!

Use %% for every % in the date format string.

$sql =3D sprintf("SELECT DATE_FORMAT(events_date, '%%b. %%D, %%Y') as Da=
te, =

events_title as Event, events_description as Description FROM events ORD=
ER =

BY Date ASC");

Then again, if this is your real statement, why even bother with the =

sprintf()? Only usefull for inserting/updating/searching on 'unknown' =

variables.
-- =

Rik Wasmus

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация