Converting Dates for a mysql database

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
gerrymac
Forum Newbie
Posts: 15
Joined: Sat Mar 13, 2004 6:19 am

Converting Dates for a mysql database

Post by gerrymac »

Hi

The system that i am currrently developing has a booking form. On this booing from users will have to enter a bookstart and a bookend. However the MYSQL format for dates is YYYYMMDD. This presents a problem as on this side of the world people use the format DDMMYYYY. So users will be entering dates in that format and this leads to problems with the bookings in the database as they are in the wrong format. Does anyone know of a way in which i could convert the dates into the correct format? The fields bookstart and bookend are type DATE in the database

Thx

Gerry
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

The best way to do this is to have three drop down menus, one for day, one for month, one for year.

The user selects the date they want by selecting the relevent information in each drop down.

Now, when the form is submitted, you can put the information togehter in the format you require becuase you have each piece of information separate.

I believe this is the best way so as to illimate user input errors.

Mark
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Bech100 wrote:I believe this is the best way so as to illimate user input errors.
I agree.

You can also use different text-fields, but that can still create someone mistyping DD and MM for example. [php_man]checkdate[/php_man]() might be worth looking into if you are trying out different ways.
User avatar
MarK (CZ)
Forum Contributor
Posts: 239
Joined: Tue Apr 13, 2004 12:51 am
Location: Prague (CZ) / Vienna (A)
Contact:

Post by MarK (CZ) »

Maybe a bit off-topic but isn't it better to save time as unix timestamp?
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post by xisle »

Post Reply