Changing Date format

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Changing Date format

Post by Draco_03 »

Hey i use phpmyadmin

i want my date format in UK (dd/mm/yyyy) instead of US default wich is (yyyy/mm/dd)

so i tried this

Code: Select all

UPDATE `clients` SET `date` = 'uk' WHERE `date` = 'timeformat' AND `date` = 'us' LIMIT 1
but it didn t do anything..
i run it in the phpmyadmin query box.. there s no error

i have a table named clients and on field name date ......
mhh nyways can anyone tell me why or how can i change the date format

thank you
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post by xisle »

set the field type to a varchar and "SET date=DATE_FORMAT(NOW(),'%d/%m/%Y')"
or use PHP to format your date and insert that "SET date='{$newdate}'"
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

i had no error it worked well.. but i wonder.. i entered a date like today 02-12-2003 but the table don t take it as a date it s varchar so if someone in my form enter some crazy stuff let s say 99-99-9999.... will it work or it will know it s not possible.. ?

thx a lot :)
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Why not store the date in a DATE field? It will make it a lot easier to manipulate, VARCHAR's very limited when it comes to dates and times. Then you just use DATE_FORMAT() to retrieve the date in whatever format you want.

Mac
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

Okay .. i just wanted to know if i could save myself to dat_format each time i want to display it :)

but thx that what i ll do i ll put it in a date field and i ll format it at the end...

Thank you all
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post by xisle »

yeh I always store a timestamp and use
DATE_FORMAT() as well.. just giving him what he wants lol
twigletmac wrote:Why not store the date in a DATE field? It will make it a lot easier to manipulate, VARCHAR's very limited when it comes to dates and times. Then you just use DATE_FORMAT() to retrieve the date in whatever format you want.

Mac
Post Reply