I can't do DATE_FORMAT works... any ideas?

Hi all

In reviewing the fantastic book of David Powers, "PHP Solutions", I decided to work with dates in a database.

The table storing the dates is called cal_dates and is of type DATE.

All dates are stored as yyyy-mm-dd

When I write my query and add DATE_FORMAT, bombs page no matter what I try.

As in:

SELECT *.
Date_format (cal_dates, '% c/%e/%Y') AS cal_dates
OF cal_data

and I get a white screen.

So, I thought that maybe I should change the alias (the example in the book of authorities at page 390 does not use a different alias, but after struggling with it for almost 2 days, I try now what anyone):

SELECT *.
Date_format (cal_dates, '% c/%e/%Y') AS cdate
OF cal_data

and I get a white screen.

Originally, my query has been designed with a WHERE clause, because I'm selecting data in a table based on a variable, but I read somewhere that DATE_FORMAT not can be used with WHERE... which is funny, since the two examples above with omitted CASES still bomb.

The original request:

SELECT *.
OF cal_data

WHERE cal_data.page_ym = '%$dateRef '.

works PERFECTLY. It takes all the information in the relevant table to the $dateRef variable.

I wanted to use DATE_FORMAT is because I wanted to take dates in yyyy-mm-dd table and display them in a different format.

But in vain. Any ideas or thoughts would be appreciated. I'm obstructionisme.

Thanks to you all!

Sincerely,

wordman

I think that booth is onto something... If the only field in cal_data is the cal_dates so really nothing to select, only a date to put in shape. The cal_dates should also be designated AS anything other than the name, it is put in the form of. Try this: by omitting the SELECT statement and rename the cal_dates AS the_date

Date_format (cal_dates, '% c/%e/%Y') AS the_dates

OF cal_data

If this does not work, then create an AutoIncrement key, primary field in the cal_data table. Name of the field id for the query to something to select before you format the date as follows:

SELECT id, DATE_FORMAT (cal_dates, '% c/%e/%Y') AS the_dates

OF cal_data

I forgot... put a comma after the last field selection and the DATE_FORMAT function in your query, as in the example above and make sure you are echoing the_dates on the page to see the date of formatting appears.

Tags: Dreamweaver

Similar Questions

Maybe you are looking for