Jump to content

Date from a form into MySQL


fesan

Recommended Posts

Hi! :)

I'm sure this is a stupid question but I've read my eyes out and still cant figure it out!

 

I have a form where i among other data fill in a date. This is a regular textbox.

How do i get this date into my MySQL Table?

 

my date variable looks like this:

$date = "28.01.2007";

 

My collumn date is a date collumn. I also know that MySQL onlu supports date form 2007-01-28, but even when i make my variable:

$date "2007-01-28";

it wont work.

 

How do i in the correct way insert a date to my MySQL database from a single textbox in a form?

also tried to convert 3 textboxes(y-m-d) in to php date() function and then insert it into my database still no luck.

Link to comment
https://forums.phpfreaks.com/topic/88228-date-from-a-form-into-mysql/
Share on other sites

Force your users to always enter the date in the same format, then use mysql's str_to_date function...

 

http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_str-to-date

 

Or, use php's date functions if you choose.  Either way, strtotime is unreliable at best with changing date formats...

 

Using your format (xx.xx.yyyy) as an example, it can only guess what "1.11.2007" is...November 1st, or January 11th?  Users may not always use the same format by default, so you have to force them to.

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.