can anyone help?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

can anyone help?

Post by mohson »

їcode]

$query = "SELECT * FROM people ORDER BY firstname";

ї/code]

Guys,

this query displays people details including two date coloums one named dateoflastcontact and the other called datecontactagain I want these two date coloums to appear in uk date format i.e dd/mm/yy. I have tried incorporating the DATE_format function from the php manual but it has no effect can anyone help
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the DATE_FORMAT function is a MySQL function, not a php one.

Code: Select all

SELECT DATE_FORMAT('%d/%m/%y', `your_date_name`) AS `your_date_field_name` FROM `table`
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

thanks, but that willl only pull up the date what abt the other fields I want to retrieve??
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you can add them like so:

Code: Select all

SELECT DATE_FORMAT(...) ..., * FROM `table`
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

thanks,

date_name and date_field_name whats the difference my date field name is dateoflastcontact
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

both should be `dateoflastcontact` then.. sorry ;)
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

Code: Select all

$query = "SELECT DATE_FORMAT(%d/%m/%y, dateoflastcontact, datecontactagain) AS dateoflastcontact, datecontactagain, * FROM people ORDER BY firstname";
Ive tried this so that the two fields dateoflastcontact and datecontactagain appear in uk date format but im getting a sql syntax error can you spot anything that im missing
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

they require seperate calls to the function.. i.e.

Code: Select all

SELECT DATE_FORMAT(...) ..., DATE_FORMAT(...) ..., * FROM `table`
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

Sorry can you explain on my code?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

rtfm :p DATE_FORMAT(date,format)


$query = "SELECT DATE_FORMAT('%d/%m/%y, dateoflastcontact) AS dateoflastcontact, DATE_FORMAT('%d/%m/%y, datecontactagain) AS datecontactagain * FROM people ORDER BY firstname";
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

put it in exactly as you said it but it still doesnt work? any ideas??

Code: Select all

$query = "SELECT DATE_FORMAT('%d/%m/%y, dateoflastcontact) AS dateoflastcontact, DATE_FORMAT('%d/%m/%y, datecontactagain) AS datecontactagain * FROM people ORDER BY firstname";
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

missing a comma after the last datecontactagain.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

typo of death ;)




$query = "SELECT DATE_FORMAT('%d/%m/%y', dateoflastcontact) AS dateoflastcontact, DATE_FORMAT('%d/%m/%y', datecontactagain) AS datecontactagain, * FROM people ORDER BY firstname";


feyd | forgot the comma! ;)
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

sorry but put in exactly as you said and I get this error message:

Error in query: You have an error in your SQL syntax near '* FROM people ORDER BY firstname' at line 1

Code: Select all

$query = "SELECT DATE_FORMAT('%d/%m/%y', dateoflastcontact) AS dateoflastcontact, DATE_FORMAT('%d/%m/%y', datecontactagain) AS datecontactagain, * FROM people ORDER BY firstname";
any ideas??
snicolas
Forum Commoner
Posts: 97
Joined: Tue Nov 09, 2004 8:32 am

Post by snicolas »

Code: Select all

$query = "SELECT DATE_FORMAT('%d/%m/%y', 'dateoflastcontact') AS dateoflastcontact, DATE_FORMAT('%d/%m/%y', 'datecontactagain') AS datecontactagain, * FROM people ORDER BY firstname";
Post Reply