Jump to content

mysql table


user4fun

Recommended Posts

I have two fields in a table start_date and end_date. Their type is set to DATE and no matter what I ahve in the default value, it is always 0000-00-00. I want to make it in the mm-dd-yy format. What am I doing wrong?

Link to comment
Share on other sites

i've always been of the mindset to store dates as timestamps (maybe with an additional 'pretty date' field for convenience) and then output them in whatever format they need to be displayed in.how are you entering them into the database?edit: the date type expects dates in YYYY-MM-DD, fwiwhttp://www.tizag.com/mysqlTutorial/mysql-date.php

Link to comment
Share on other sites

I am not very good at this date stuff. I am about to go the easy way and force the user to enter the date in this format YYYY-MM-DD but I can see how this will create problems lolI think I am just going to do a drop down box with all the month, another for the day, and another for the year. but then my next problem will be that the date will be stored as 2011-06-17 :-)

Link to comment
Share on other sites

You can use the strtotime() and date() functions to help you.Let the user enter dates in a format they are comfortable with. If they enter 6-17-2011 you can do this to convert to a format expected by the database:$userDate = '6-17-2011'; //This would be retrieved from the $_POST array or some such$db_date = date('Y-m-d', strtotime($userDate));That way it really doesn't matter how the user enters the date as long as it's a valid format. For example, any of the following would work:6-17-1106-17-112011-6-17Jun 17, 2011June 17, 2011etc, etc.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...