Date format - correct setting but no change

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

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

Date format - correct setting but no change

Post by mohson »

Ok I thought I had sorted out my date format to print results in UK format, the code below is how I did it and I thought it worked fine:

Code: Select all

DATE_FORMAT(dateoflastcontact, '%d/%m/%y') 
AS dateoflastcontact, DATE_FORMAT(datecontactagain, '%d/%m/%y') 
AS datecontactagain
when I enter 20-02-05 into dateoflast contact(uk time format - dd-mm-yy) in my form it gives me :
05/02/20

and when I enter 21-02-05 into datecontactagain (uk time format - dd-mm-yy) it gives me : 05/02/21

the mysql manual explains how to do it and I followed that to the letter plus some advice off this forum but still it remains the same?

Anyone got any advice or can anyone see anything wrong with this?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you must insert the date into mysql using mysql's format.. for instance 20-02-05 is February 5th, 2020 to mysql.

if you have 4.1.1 or later, you can use STR_TO_DATE() to format the proper date for you.

http://dev.mysql.com/doc/mysql/en/date- ... tions.html
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

Thanks feyd, I know this as you explained it to me before and I am inserting it in mysqls standard format. The code I have displayed relates to printing data - as from what I understand you must insert it as the normal mysql format BUT when you do the select query and print the results you can adjust the format. The code above relates to my select query not my insert query.

anymore advice would be helpful relating to the select query? can you see anything wrong with the date format part (displayed) of my select query?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the date was inserted wrong in the database. The selection is fine.
Post Reply