date format question

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
User avatar
Obadiah
Forum Regular
Posts: 580
Joined: Mon Jul 31, 2006 9:13 am
Location: Ashland, KY
Contact:

date format question

Post by Obadiah »

ok...if i use the date format for a field in my database it stores as (YYYY-MM-DD) right? ok, now say if while filling out the form someone puts in December 30, 1973 or 12-30-1973 or simply 19731230(same day without dashes) will i get a db error?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

try it.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

feyd wrote:try it.
Quite possibly the best advice a developer can give another developer. What is the worst that could happen?
User avatar
zeek
Forum Commoner
Posts: 48
Joined: Mon Feb 27, 2006 7:41 pm

lol, now that you know the answer to your question

Post by zeek »

lol, now that you know the answer to your question...

If the date isn't properly formatted, it will not be stored. You could try:

Code: Select all

$formatted_date = date('Y-m-d', strtotime($raw_date) );
But the proper way to handle this issue is to simply force the formatting in the form itself. Instead of just giving a text field for the date, give a seperate dropdown for day, month, and year. Then just piece them together in your code.


PS. Hey feyd, you like my proper formatting? Uhu
Post Reply